[PLUG-Devel] python exec probs

Darrin Chandler dwchandler at stilyagin.com
Thu Mar 25 14:47:55 MST 2010


Hans!

On Thu, Mar 25, 2010 at 02:33:59PM -0700, der.hans wrote:
> 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]

This looks correct. Exec format error sounds like /var/tmp/test.sh
either isn't marked executable or it's not actually a shell script or
something. Does "/var/tmp/test.sh /var/tmp/file.txt" work at the shell
prompt?

> 
> # 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
> _______________________________________________
> PLUG-devel mailing list  -  PLUG-devel at lists.PLUG.phoenix.az.us
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-devel
> 

-- 
Darrin Chandler            |  Phoenix BSD User Group  |  MetaBUG
dwchandler at stilyagin.com   |  http://phxbug.org/      |  http://metabug.org/
http://www.stilyagin.com/  |  Daemons in the Desert   |  Global BUG Federation


More information about the PLUG-devel mailing list