subprocess.popen question

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Jun 22 01:10:29 EDT 2007


En Fri, 22 Jun 2007 01:05:36 -0300, Eric_Dexter at msn.com  
<Eric_Dexter at msn.com> escribió:

>> >> >> cmd = ["gawk", "-f", "altertime.awk", "-v", "time_offset=4", "-v",
>> >> >> "outfile=testdat.sco", "i1.sco"]
>> >> >> 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?
>
> gawk is installed..  I do fine when I just call gawk I get all the
> options to use with it but the minute I try to use the options with it
> I have problems.  I have done it with batch files but then I would
> have to write out a batch file and then run the batch file.  seems
> like more work than I should have to do to use options with a command
> line program..  I have done this in other cases with os.startfile and
> other cases and would like to fix it.

Ok, but please check *what* are the arguments to Popen. If cmd is a *list*  
as shown on the first quoted line on this message, you should call  
subprocess.Popen(cmd, ...) as shown on the third line on this message, but  
your traceback shows that you are using Popen([cmd], ...)
Can you see the difference?

-- 
Gabriel Genellina




More information about the Python-list mailing list