subprocess.popen question

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Jun 21 08:22:44 CEST 2007


En Wed, 20 Jun 2007 22:28:06 -0300, Eric_Dexter at msn.com  
<Eric_Dexter at msn.com> escribió:
> On Jun 20, 7:50 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> wrote:
>> En Wed, 20 Jun 2007 20:02:52 -0300, Eric_Dex... at msn.com
>> <Eric_Dex... at msn.com> escribió:
>> > On Jun 20, 1:46 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
>> > wrote:
>>
>> >> 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
>>
>> >  C:\dex_tracker\pipe1.py
>> > Traceback (most recent call last):
>> >  File "C:\dex_tracker\pipe1.py", line 14, in
>> > last_line = subprocess.Popen([cmd],
>> > stdout=subprocess.PIPE).communicate()[0]
>> >  File "C:\Python25\lib\subprocess.py", line 593, in __init__
>> > errread, errwrite)
>> >  File "C:\Python25\lib\subprocess.py", line 793, in _execute_child
>> > startupinfo)
>> > WindowsError: [Error 2] The system cannot find the file specified
>> > Script terminated.
>>
>> > I can write it out as a batch file and then run it but that is a messy
>> > hack..
>>
>> If cmd is a list of arguments, like the example above, you should use
>> subprocess.Popen(cmd,...) (like the example above, too).
>
> I had cut and pasted the example in to get that error...  could it be
> a problem with ms windows??? (I am at a library computer befour work
> so that ended my testing)

Note the call to subprocess.Popen - is the first argument [cmd] or cmd?
What do you get with print repr(cmd)?
Do you have gawk installed on that machine too?

-- 
Gabriel Genellina




More information about the Python-list mailing list