On Thu, 2009-03-26 at 15:23 -0700, harijay wrote: > 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) >
Ask yourself what you are trying to do: * Run an executable * pass arguments to the executable * Use a string standard input to the call Then re-read over the subprocess module and it should become clearer to you. -- http://mail.python.org/mailman/listinfo/python-list