0

I am connecting to a server through PHP SSH and then using exec to run a python program on that server.

If I connect to that server through putty and execute the same command through command line, I get result like:

Evaluating....

Connecting....

Retrieving data....

1) Statement 1

2) Statement 2

.

.

.

N) Statement N

Python program is written by somebody else...

When I connect through SSH php, I can execute $ssh->exec("ls") and get the full results as proper as on server command line. But when I try $ssh->exec("python myscript.py -s statement 0 0 0"); I couldn't get the full results but I get a random line as an ouput.

In general, if somebody had experienced the same issue and solved, please let me know.

Thanks

2
  • What random lines ? Can you show example ? Commented Oct 13, 2016 at 11:00
  • I am sorry I cannot show the output. But consider having 23) statement 23 as an output. But you were supposed to have ouput like in question Commented Oct 13, 2016 at 11:02

1 Answer 1

2

Perhaps it's caused by buffering of the output. Try adding the -u option to your Python command - this forces stdout, stdin and stderr to be unbuffered.

Sign up to request clarification or add additional context in comments.

4 Comments

Where in this line? $ssh->exec("python myscript.py -s statement 0 0 0");
One more thing I want to ask is: If I achieve the output by your method, what is the way to proper architecture the output? Like json or xml?
Add -u after python: $ssh->exec("python -u myscript.py -s statement 0 0 0")
Proper architecture? It's hard to say without any details. Either has its place, but if the code is already written, I'd just use that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.