running shelscript inside python

harijay harijay at gmail.com
Thu Mar 26 23:23:30 CET 2009


Hi
I want to run shell scripts of the following kind from inside python
and for some reason either the os.system or the subprocess.call ways
are not working for me .

I am calling a fortran command (f2mtz ) with some keyworded input that
is normally piped (<<)  in.
The section of code that deals with the shell script is as  follows

script="""HKLIN %s HKLOUT %s <<eof
SYMM %s
CELL %s
format '(3f4.0,f11.2,f8.2,f7.3,4f11.3)'
skipline 0
LABOUT H K L IP FOMS PHIS HLA HLB HLC HLD
CTYPOUT H H H I W P A A A A
END
eof
""" %(options.phs,options.mtzfile,options.symm,cellparams)
import subprocess
subprocess.call(["f2mtz" , script])

Normally I would type the commands above into a shell script and then
execute it
for example a file (tmp.sh)

#!/usr/bin/sh
f2mtz HKLIN 32_4run1.phs HKLOUT 32_4run1.mtz <<eof
SYMM p1
CELL 79.814 102.639 153.627 82.465 75.531 73.450
format '(3f4.0,f11.2,f8.2,f7.3,4f11.3)'
skipline 0
LABOUT H K L IP FOMS PHIS HLA HLB HLC HLD
CTYPOUT H H H I W P A A A A
END
eof

And then run that script
"sh tmp.sh"


When I try subprocess.call(["f2mtz" , script]) or os.system("f2mtz %s"
% script)

It does not seem to work the same way. ANy ideas how to get around
this

Thanks a lot for your help
Hari



More information about the Python-list mailing list