Python, equivalent of set command

Jeffrey Schwab jeff at schwabcenter.com
Mon Mar 27 10:33:35 EST 2006


loial wrote:
> In unix shell script I can do the following to get the status and
> values returned by a unix command
> 
> OUTPUT=`some unix command`
> STATUS=$?
> if [ $STATUS -ne 0 ]
> then
>   exit 1
> else
>   set $OUTPUT
>   VAL1=$1
>   VAL2=$2
>   VAL3=$3
> fi
> 
> How can I achieve the same in python?
> 
> I know how to run it via the os.system command and return the status,
> but how do I return the values too?

http://docs.python.org/lib/node241.html

6.8.3.1 Replacing /bin/sh shell backquote

output=`mycmd myarg`
==>
output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]

The popen object also has a 'returncode' attribute.



More information about the Python-list mailing list