Trouble with subprocess.call(...) and zsh script (OSError: [Errno 8] Exec format error)

  • Thread starter Michael George Lerner
  • Start date
M

Michael George Lerner

Hi,

(Python 2.5, OS X 10.4.10)
I have a program called pdb2pqr on my system. It is installed so that
"pdb2pqr" is in my path and looks like:

#\!/bin/zsh -f
/sw/share/pdb2pqr/pdb2pqr.py "$@"

When I call it via this script:

#!/usr/bin/env python
import subprocess
import tempfile
args = ('/sw/bin/pdb2pqr','--help')
output_file = tempfile.TemporaryFile(mode="w+")
print "Running",args
retcode =
subprocess.call(args,stdout=output_file.fileno(),stderr=subprocess.STDOUT)
output_file.close()

I get this error:

localhost~/tmp$ ./x.py
Running ('/sw/bin/pdb2pqr', '--help')
Traceback (most recent call last):
File "./x.py", line 9, in <module>
retcode =
subprocess.call(args,stdout=output_file.fileno(),stderr=subprocess.STDOUT)
File "/sw/lib/python2.5/subprocess.py", line 443, in call
return Popen(*popenargs, **kwargs).wait()
File "/sw/lib/python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
File "/sw/lib/python2.5/subprocess.py", line 1051, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error

But when I change it to directly call the script that the zsh script
calls like this:

args = ('/sw/share/pdb2pqr/pdb2pqr.py','--help')

everything works:

localhost~/tmp$ ./x.py
Running ('/sw/share/pdb2pqr/pdb2pqr.py', '--help')

This is with 2.5 on OS X 10.4.10. I'm happy to provide whatever
additional information might be useful.

Thanks,

-michael
 
R

Rob Wolfe

Michael George Lerner said:
Hi,

(Python 2.5, OS X 10.4.10)
I have a program called pdb2pqr on my system. It is installed so that
"pdb2pqr" is in my path and looks like:

#\!/bin/zsh -f

Are you sure that this shebang is correct?

I've tested that on bash and have similar error:

# t1.sh

#\!/bin/sh
echo "t1"
from subprocess import call
call(['./t1.sh'])
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/subprocess.py", line 413, in call
return Popen(*args, **kwargs).wait()
File "/usr/lib/python2.4/subprocess.py", line 543, in __init__
errread, errwrite)
File "/usr/lib/python2.4/subprocess.py", line 975, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error

But running that directly through the shell works:
t1
0

However this script works fine also without `shell=True` option:

# t2.sh

#!/bin/sh
echo "t2"
t2
0


HTH,
Rob
 
M

Michael George Lerner

Are you sure that this shebang is correct?

Well, it's correct in the sense that I have faithfully reproduced the
contents of the file. I didn't write it, though.

I don't know what the extra backslash is for. I suppose I'll contact
the authors and find out.

Any ideas how to make it work with the strange shebang syntax?

Thanks,

-michael
I've tested that on bash and have similar error:

# t1.sh

#\!/bin/sh
echo "t1"
from subprocess import call
call(['./t1.sh'])

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/subprocess.py", line 413, in call
return Popen(*args, **kwargs).wait()
File "/usr/lib/python2.4/subprocess.py", line 543, in __init__
errread, errwrite)
File "/usr/lib/python2.4/subprocess.py", line 975, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error

But running that directly through the shell works:
call(['./t1.sh'], shell=True)

t1
0

However this script works fine also without `shell=True` option:

# t2.sh

#!/bin/sh
echo "t2"

t2
0

HTH,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,828
Messages
2,569,736
Members
45,518
Latest member
vlonesshirt

Latest Threads

Top