subprocess.popen question

Eric_Dexter at msn.com Eric_Dexter at msn.com
Wed Jun 20 18:49:55 EDT 2007


On Jun 20, 1:46 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Wed, 20 Jun 2007 12:27:47 -0300, Eric_Dex... at msn.com  
> <Eric_Dex... at msn.com> escribió:
>
> > I am trying to modify a programming example and I am coming up with
> > two problems...  first is that I can't seem to pass along the
> > arguments to the external command (I have been able to do that with
> > the old module and cmd is the command I wish to try) all the output
> > seems to be returned as one line (at least when I run the program in
> > spe).
>
> > import subprocess
> > from os import system
> > cmd = """gawk -f altertime.awk -v time_offset=4 -v
> > outfile="testdat.sco" "i1.sco" """
> > #subprocess.Popen.
> > last_line = subprocess.Popen(['gawk.exe'],
> > stdout=subprocess.PIPE).communicate()[0]
>
> You build what appears to be the desired command line, but execute  
> gawk.exe instead.
> Better split the arguments beforehand:
> cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v",  
> "outfile=testdat.sco", "i1.sco"]
> Now, what do you want to do with the output? Printing it line by line?
> output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
> lines = output.splitlines()
> for line in lines:
>    print line
>
> --
> Gabriel Genellina

I had one test where I had cmd in place of gawk and one everything was
in place of gawk..  I haven't tried what you have listed yet (I am
getting ready to go to work so may have to wait until tommorow to try
it)  THanks for the help




More information about the Python-list mailing list