>>>> - If you do need to parse stderr, there are some alternatives to the
>>>> current approach. Popen.communicate() returns a (stdout, stderr)
>>>> tuple and waits for the process to terminate. If the output from
>>>> beadm is expected to be small, this would be the way to go.
>>>>
>>>>
>>> I have regenerated the webrev to use communicate. See
>>> http://cr.opensolaris.org/~padraig/ips-6549-v2/.
>>>
>>
>> The lines that you added look fine; however, I'm curious why you removed
>> the stdout -> /dev/null redirection. Is stdout already closed in
>> packagemanager?
>>
>>
>
> My understanding was that stdout was returned by communicate. I do not
> expect any output from stdout and choose to ignore it if present.
Stdout is returned by communicate if you supply subprocess.PIPE as the
argument to stdout, otherwise it just goes wherever stdout of the parent
process goes.
You can test this yourself, if you'd like, by the following example:
$ python
Python 2.4.4 (#1, Aug 27 2007, 08:26:51) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> cmd = ["/usr/bin/ls"]
>>> proc = subprocess.Popen(cmd, stderr=subprocess.PIPE)
a_term.sh bc_term.sh h_xterm.sh pyzor willneed
a_xterm.sh bugster hist pyzord xskel
b_dtcm.sh cdcc j_term.sh sccshist
b_term.sh dccif-test j_xterm.sh startmail.sh
b_xclock.sh dccproc pstart suntea
b_xterm.sh h_term.sh pullmail.sh suntea.jnlp
>>> out = proc.communicate()
>>> print out
(None, '')
>>> nullout = open("/dev/null", "wb")
>>> proc = subprocess.Popen(cmd, stdout=nullout, stderr=subprocess.PIPE)
>>> out = proc.communicate()
>>> print out
(None, '')
>>> proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> out = proc.communicate()
>>> print out
('a_term.sh\na_xterm.sh\nb_dtcm.sh\nb_term.sh\nb_xclock.sh\nb_xterm.sh\nbc_term.sh\nbugster\ncdcc\ndccif-test\ndccproc\nh_term.sh\nh_xterm.sh\nhist\nj_term.sh\nj_xterm.sh\npstart\npullmail.sh\npyzor\npyzord\nsccshist\nstartmail.sh\nsuntea\nsuntea.jnlp\nwillneed\nxskel\n',
'')
>>>
In the first case, stdout goes to stdout in my terminal since that's
where the parent process's output goes. In the second case it goes to
/dev/null. In the third case, I've specified PIPE, so it gets placed in
slot 0 of the tuple from communicate.
My guess is that you probably still want to send this to /dev/null, but
I don't know if packagemanager closes stdin/stdout when it starts.
HTH,
-j
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss