[Tutor] Popen4 and Paths Containing Spaces

Gooch, John John.Gooch at echostar.com
Wed Jun 15 15:55:42 CEST 2005

I am having problems with using the Winzip command line tools and Python.

Here is an example of the several dozen different ways I have tried to
execute the Wzzip.exe utility with arguments using
popen2 -

This works (just runs the utility with not arguments ):
	cmd = "\"d:/program files/winzip/wzzip.exe\"" 
	results = popen2.popen4( cmd )

However this fails miserably:
    testpath = "D:/Program Files/WebTrends/SmartSource Data
    cmd = "\"d:/program files/winzip/wzzip.exe\" -ma test.zip \"" + testpath
+ "\"" 
    results = popen2.popen4( cmd )

If I set the script to print out the value stored in the variable "cmd" it
says this:
	"d:/program files/winzip/wzzip.exe\" -ma test.zip "D:/Program
Files/WebTrends/SmartSource Data Collector/weblog/*.log"

Which if I paste it onto the command line, does exactly what I intend it to
do. But for some reason, popen2.popen4(cmd) gives this as output ( from
stderr ):
	'd:/program' is not a file or command

My only guess is that popen2.popen4 is parsing the string differently than
the "print" command does, because print recognizes that the backslash is
escaping the double quotes ( e.g. "\"" ) in the string, and popen does not.
On the other hand, it appears to be recognizing it in my first example, so
that is what is really confusing me. It isn't consistent at all. 

Any ideas?  

John A. Gooch
"May the Python-force be with you...always."
Systems Administrator
EchoStar Satellite L.L.C.
Desk: 720-514-5708 

-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf
Of Danny Yoo
Sent: Tuesday, June 14, 2005 4:21 PM
To: Pujo Aji
Cc: Tutor
Subject: Re: [Tutor] can't see emacs timer in action

On Tue, 14 Jun 2005, Pujo Aji wrote:

> I tried this code in emacs.
> for i in range(3):
>   time.sleep(1)
>   print i
> It shows the result but total result not second per second.

Hi Pujo,

In Emacs, you may want to first start up a Python subprocess by using the

    C-c !

and then run Python buffers with:

    C-c C-c

Best of wishes!

Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list