Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Problem using subprocess.Popen on windows

Reply
Thread Tools

Re: Problem using subprocess.Popen on windows

 
 
Tim Golden
Guest
Posts: n/a
 
      10-07-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Windows logon Screen in Windows 7 and Windows 2008 Tech Guy Windows 64bit 0 04-27-2011 12:59 PM
!Windows Live Mail replace Outlook Express on Windows XP and Windows Mail on Vista... Max Burke NZ Computing 8 05-18-2007 12:10 AM
Windows Explorer error using Windows 2000 Rod Computer Support 5 05-23-2006 06:53 PM
Using Windows XP x64 Drivers with Windows Server 2003 x64 Steve Graddy Windows 64bit 9 10-22-2005 04:27 AM
Using a Windows XP 64 bit print driver on a 32 bit Windows 2003 Print Server Alex Griffin Windows 64bit 14 07-27-2005 04:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57