Problem using subprocess.Popen on windows

2007-10-07 Thread jorma kala
Hi,

I get an error that I don't understand when using the subprocess module on
Windows.
I guess I'm missing out something very basic.
For instance, to execute and capture the output of the ms-dos dir command, I
tried the following:


from subprocess import *

p1 = Popen([dir],  stdout=PIPE)
output = p1.communicate()[0]


But I get a WindowsError : [Error 2]  File Not Found


The exact traceback is :

Traceback (most recent call last):
  File pipe2.py, line 5, in module
p1 = Popen([dir],  stdout=PIPE)
  File C:\Python25\lib\subprocess.py, line 593, in __init__
errread, errwrite)
  File C:\Python25\lib\subprocess.py, line 815, in _execute_child
startupinfo)
WindowsError: [Error 2] Le fichier spÚcifiÚ est introuvable


Do you know what is missing in my code?

Thanks a lot

jorma
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problem using subprocess.Popen on windows

2007-10-07 Thread Tim Golden
jorma kala wrote:
 I get an error that I don't understand when using the subprocess module 
 on Windows.
 I guess I'm missing out something very basic.
 For instance, to execute and capture the output of the ms-dos dir 
 command, I tried the following:
 
 from subprocess import *
 
 p1 = Popen([dir],  stdout=PIPE)
 output = p1.communicate()[0]
 
 But I get a WindowsError : [Error 2]  File Not Found

That's because dir isn't an executable file in its
own right, merely a subcommand of the command shell.
Do this:

code
from subprocess import *

p1 = Popen (dir, shell=True, stdout=PIPE)
print p1.communicate ()[0]

/code

TJG
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem using subprocess.Popen on windows

2007-10-07 Thread Nicholas Bastin
On 10/7/07, jorma kala [EMAIL PROTECTED] wrote:
  from subprocess import *

  p1 = Popen([dir],  stdout=PIPE)
  output = p1.communicate()[0]


  But I get a WindowsError : [Error 2]  File Not Found

Tim answered your actual question, but why are you doing this in the
first place?  The Python standard library provides all the
functionality that dir will provide and you don't have to parse the
output...

Look into http://www.python.org/doc/lib/os-file-dir.html, and
specifically, os.listdir(path).

--
Nick
-- 
http://mail.python.org/mailman/listinfo/python-list