[PLUG-Devel] python exec probs
der.hans
PLUG at LuftHans.com
Thu Mar 25 14:33:59 MST 2010
moin moin,
I don't speak python, but I need to get something simple done via python.
Currently I'm trying to pass an argument to an external program and
capture the output.
I'm running Ubuntu 9.10 with python 2.6, but will be deploying on CentOS
with python 2.4.
Apparently the subprocess module was introduced in 2.4 and is replacing
all other mechanims for this.
http://docs.python.org/library/subprocess.html
$ cat /var/tmp/test.py
#!/usr/bin/python
import subprocess as sub
# shell_cmd = "/var/tmp/test.sh"
# file='/var/tmp/file.txt'
# p = sub.Popen( [shell_cmd, file], stdout=sub.PIPE )
p = sub.Popen(["/var/tmp/test.sh", "/var/tmp/file.txt"], stdout=sub.PIPE)
output = p.communicate()[0]
# print "%(output)d output" % { 'output': output }
$ /var/tmp/test.py
Traceback (most recent call last):
File "/var/tmp/test.py", line 9, in <module>
p = sub.Popen(["/var/tmp/test.sh", "/var/tmp/file.txt"],
stdout=sub.PIPE)
File "/usr/lib/python2.6/subprocess.py", line 621, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1126, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
$ ls -l /var/tmp/test.sh
-rwxr-xr-x 1 lufthans lufthans 268 2010-03-25 14:13 /var/tmp/test.sh
$ /var/tmp/test.sh
2112
If I leave the square brackets off the command and file I get an error
about bufsize not being an integer. If I leave the brackets off and remove
the argument I still get the Exec format error.
How can I fix my code to get this working?
ciao,
der.hans
--
# http://www.LuftHans.com/Classes http://www.TwoGeekTechs.com/
# Director of Engineering, FonWallet Transaction Solutions, Inc.
# "If your girlfriend is crying crocodile tears it's because she's either
# got salt in her eye or she's been listening to Air Supply."
# -- Alice Cooper, 08Mar2005
More information about the PLUG-devel
mailing list