| | |
New to Python, help printing output of system calls
![]() |
•
•
Join Date: Aug 2008
Posts: 1
Reputation:
Solved Threads: 0
I'm new to Python and not anywhere near a competent programmer.
Anyway, if someone could help me get over this hump, I'd appreciate it.
I need to write a Python script that calls commands from the OS that may have lengthy output. Let's say I want to see the results of an rsync between two directories. I'd like to print the output in real-time to a web page.
My web page calls the Python script. No problem.
My Python script does a system call to rsync. No problem.
Here's were I get puzzled. No output from the rsynch makes it to the screen. It runs, but I can't see that anything is happening until the rsync is finished.
What would be the correct technique for doing this kind of thing? Basically I want to call system functions and have their status output appear just as I would have seen it from the command line.
Thanks for any tips.
Anyway, if someone could help me get over this hump, I'd appreciate it.
I need to write a Python script that calls commands from the OS that may have lengthy output. Let's say I want to see the results of an rsync between two directories. I'd like to print the output in real-time to a web page.
My web page calls the Python script. No problem.
My Python script does a system call to rsync. No problem.
Here's were I get puzzled. No output from the rsynch makes it to the screen. It runs, but I can't see that anything is happening until the rsync is finished.
What would be the correct technique for doing this kind of thing? Basically I want to call system functions and have their status output appear just as I would have seen it from the command line.
Thanks for any tips.
It would be easier if we could see the python line which runs the system call.
A possible solution to your problem is to start the system call without waiting for it's completion, using
A possible solution to your problem is to start the system call without waiting for it's completion, using
subprocess.Popen (see http://docs.python.org/lib/node533.html). Then, once you have a child process running, print it's output with a loop, like this python Syntax (Toggle Plain Text)
child = Popen(...) for line in child.stdout: print line
![]() |
Other Threads in the Python Forum
- Previous Thread: Opening pipelines with python ?
- Next Thread: Need Help With a Function....
| Thread Tools | Search this Thread |
abrupt alarm ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui halp heads homework http ideas import input java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib





