Hi,
What is the difference between:
1) getting the returncode directly from the subprocess object
2) calling poll() on the subprocess object?
Here is an example:
import subprocess
p = subprocess.Popen("ls", stdout=subprocess.PIPE)
print p.returncode
print p.poll()
print
print p.stdout.read()[:5]
print
print p.returncode
print p.poll()
print p.returncode
--output:--
None
None
10tes
None
0
0 4 17402
On Sep 20, 1:17 pm, 7stud <bbxx789_0...@yahoo.comwrote:
Hi,
What is the difference between:
1) getting the returncode directly from the subprocess object
2) calling poll() on the subprocess object?
Here is an example:
import subprocess
p = subprocess.Popen("ls", stdout=subprocess.PIPE)
print p.returncode
print p.poll()
print
print p.stdout.read()[:5]
print
print p.returncode
print p.poll()
print p.returncode
--output:--
None
None
10tes
None
0
0
Hmm....after a little more testing, I don't think returncode
dynamically updates:
import subprocess
import time
p = subprocess.Popen("ls", stdout=subprocess.PIPE)
print p.returncode
time.sleep(5)
print p.returncode
time.sleep(2)
print p.returncode
print p.stdout.read()[:5]
print p.returncode
--output:--
None
None
None
10tes
None
On Sep 20, 1:25 pm, 7stud <bbxx789_0...@yahoo.comwrote:
On Sep 20, 1:17 pm, 7stud <bbxx789_0...@yahoo.comwrote:
Hi,
What is the difference between:
1) getting the returncode directly from the subprocess object
2) calling poll() on the subprocess object?
Here is an example:
import subprocess
p = subprocess.Popen("ls", stdout=subprocess.PIPE)
print p.returncode
print p.poll()
print
print p.stdout.read()[:5]
print
print p.returncode
print p.poll()
print p.returncode
--output:--
None
None
10tes
None
0
0
Hmm....after a little more testing, I don't think returncode
dynamically updates:
import subprocess
import time
p = subprocess.Popen("ls", stdout=subprocess.PIPE)
print p.returncode
time.sleep(5)
print p.returncode
time.sleep(2)
print p.returncode
print p.stdout.read()[:5]
print p.returncode
--output:--
None
None
None
10tes
None
....but then when is p.returncode set? And what good is it?
On 9/20/07, 7stud <bb**********@yahoo.comwrote:
On Sep 20, 1:25 pm, 7stud <bbxx789_0...@yahoo.comwrote:
On Sep 20, 1:17 pm, 7stud <bbxx789_0...@yahoo.comwrote:
Hi,
What is the difference between:
1) getting the returncode directly from the subprocess object
2) calling poll() on the subprocess object?
Here is an example:
import subprocess
p = subprocess.Popen("ls", stdout=subprocess.PIPE)
print p.returncode
print p.poll()
print
print p.stdout.read()[:5]
print
print p.returncode
print p.poll()
print p.returncode
--output:--
None
None
10tes
None
0
0
Hmm....after a little more testing, I don't think returncode
dynamically updates:
import subprocess
import time
p = subprocess.Popen("ls", stdout=subprocess.PIPE)
print p.returncode
time.sleep(5)
print p.returncode
time.sleep(2)
print p.returncode
print p.stdout.read()[:5]
print p.returncode
--output:--
None
None
None
10tes
None
...but then when is p.returncode set? And what good is it?
AFAICT p.returncode is only set by Popen methods. It doesn't
automatically get set by the OS internals that manage the actual
process.
One place where it is useful is when using Popen's communicate()
method, which returns (stdout,stderr), but not the return code. Also
it lets you call poll() but not have to save poll()'s return value.
On Sep 20, 3:24 pm, David <wizza...@gmail.comwrote:
On 9/20/07, 7stud <bbxx789_0...@yahoo.comwrote:
On Sep 20, 1:25 pm, 7stud <bbxx789_0...@yahoo.comwrote:
On Sep 20, 1:17 pm, 7stud <bbxx789_0...@yahoo.comwrote:
Hi,
What is the difference between:
1) getting the returncode directly from the subprocess object
2) calling poll() on the subprocess object?
Here is an example:
import subprocess
p = subprocess.Popen("ls", stdout=subprocess.PIPE)
print p.returncode
print p.poll()
print
print p.stdout.read()[:5]
print
print p.returncode
print p.poll()
print p.returncode
--output:--
None
None
10tes
None
0
0
Hmm....after a little more testing, I don't think returncode
dynamically updates:
import subprocess
import time
p = subprocess.Popen("ls", stdout=subprocess.PIPE)
print p.returncode
time.sleep(5)
print p.returncode
time.sleep(2)
print p.returncode
print p.stdout.read()[:5]
print p.returncode
--output:--
None
None
None
10tes
None
...but then when is p.returncode set? And what good is it?
AFAICT p.returncode is only set by Popen methods. It doesn't
automatically get set by the OS internals that manage the actual
process.
One place where it is useful is when using Popen's communicate()
method, which returns (stdout,stderr), but not the return code. Also
it lets you call poll() but not have to save poll()'s return value.
I didn't understand your post when I first read it, but after looking
at my output again, and rereading your post, I get it now. In case
someone else doesn't understand it: returncode is not set by the
child process--ever. return code starts off with a default value of
None, and it remains None until you call a method in the subprocess
module, like poll() or wait(). Those methods set and then return
returncode. As a result, if you want to know what the status of the
child process is, you have to call either poll() or wait(). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Will |
last post by:
I have this bit of code:
#!/usr/bin/python
import subprocess
calc = subprocess.Popen("dc", stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
max = 5
|
by: Christoph Haas |
last post by:
Evening,
I'm having trouble with running a process through Python 2.4's
subprocess module. Example code:
========================================================
def run(command):
run =...
|
by: Corey Wallis |
last post by:
Dear All,
I'm currently working on a project that needs to collect the output of
the JHOVE application. More information about the application is
available at this website:
...
|
by: Jim |
last post by:
Hello,
I need a program that will traverse a directory tree to ensure that
there
are unix-style line endings on every file in that tree that is a text
file.
To tell text files from others I...
|
by: bhunter |
last post by:
Hi,
I've used subprocess with 2.4 several times to execute a process, wait
for it to finish, and then look at its output. Now I want to spawn
the process separately, later check to see if it's...
|
by: jakub.hrozek |
last post by:
Hello,
My program uses the subprocess module to spawn a child and capture its
output. What I'd like to achieve is that stdout is parsed after the
subprocess finishes, but anything that goes to...
|
by: grayaii |
last post by:
There are so many threads on this subject, but I ran across a
situation on Windows that I can't figure out.
I'm trying to run this little command-line exe and when I launch like
this, it hangs:...
|
by: rparimi |
last post by:
I am trying to redirect stderr of a process to a temporary file and
then read back the contents of the file, all in the same python
script. As a simple exercise, I launched /bin/ls but this doesn't...
|
by: Samuel A. Falvo II |
last post by:
I have a shell script script.sh that launches a Java process in the
background using the &-operator, like so:
#!/bin/bash
java ... arguments here ... &
In my Python code, I want to invoke...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |