Bugs item #774546, was opened at 2003-07-20 09:29
Message generated for change (Comment added) made by facundobatista
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=774546&group_id=5470

Category: Python Library
Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Philippe Fremy (pfremy)
Assigned to: Nobody/Anonymous (nobody)
Summary: popen does not like filenames with spaces

Initial Comment:
The argument for the target executable are passed as a 
string to popen. The problem is that with filenames which 
contains spaces, the argument breaking routine will fail 
and create two arguments for one filename. 
 
It would be more convenient if one could pass the 
argument to popen as a list of string. 
 
 

----------------------------------------------------------------------

>Comment By: Facundo Batista (facundobatista)
Date: 2005-01-15 16:46

Message:
Logged In: YES 
user_id=752496

Think that this should be closed with "Won't fix" specially
now that we have the subprocess module.

----------------------------------------------------------------------

Comment By: Facundo Batista (facundobatista)
Date: 2005-01-15 16:46

Message:
Logged In: YES 
user_id=752496

Please, could you verify if this problem persists in Python 2.3.4
or 2.4?

If yes, in which version? Can you provide a test case?

If the problem is solved, from which version?

Note that if you fail to answer in one month, I'll close this bug
as "Won't fix".

Thank you! 

.    Facundo

----------------------------------------------------------------------

Comment By: Peter Åstrand (astrand)
Date: 2003-11-01 13:44

Message:
Logged In: YES 
user_id=344921

popen5 (http://www.lysator.liu.se/~astrand/popen5/) uses a
sequence argument instead of a string, and has no problems
with whitespace. Also, it supports connecting several
subprocesses together (feeding the output from one command
into another). 

----------------------------------------------------------------------

Comment By: Philippe Fremy (pfremy)
Date: 2003-09-01 07:41

Message:
Logged In: YES 
user_id=233844

I was trying to use python as a shell replacement for simple 
scripts, but I was disapppointed by the poor level of support of 
python for those things. 
 
In my case, the list of files was pulled from a command and 
passed to another one. 
 
I have some suggestions on how to improve python shell 
scripting capability. Right now, as soon as you want to do 
something a little bit complicated, like feeding a program (let's 
say grep) from the output of another program and checking the 
output and the exit status is quite complicated. 
 
For such an interface to be good, it has to provide _very_ easy 
way to: 
- read stdout from a command 
- provide stdin to a command 
- read exit status of a command. 
- pipe a command into another one 
 
Let's say I want to run the equivalent of 
find . -name '*.cpp' | grep -i toto 
 
My suggested interface to run a simple command would be as 
following: 
cmd( "find", ".", "-name", "*.cpp")  
 
This defines a command to be run. To be versatile, this would 
have to accept although the following format: 
 
cmd( [ "find", ".", "-name", "*.cpp" ] 
) 
cmd( "find", [  ".", "-name", "*.cpp" ] 
) 
which are slightly different ways of spawning a command. I think 
all these three ways have a usage pattern. 
 
To actually execute the command, you woud do: 
cmd( "find", ".", "-name", "*.cpp" 
).go() 
 
This create an object which has  
 
 
 
To run it, you just apply the go() method: 
 
cmd( "find", ".", "*.cpp" ).go() 
 
This could return a tuple (stdout, stderr, return_code) 
 
Now, if you want to pipe a command into another one, we can 
either override the operator | or write it manually. My initial 
command would become: 
cmd( "find", ".", "-name", "*.cpp" 
).pipe().cmd( "grep", "-i", "toto" 
) 
 
I dislike using a syntax like cmd().pipe( cmd ) because piping 
multiple commands would required parenthesis nesting which 
does not look nice. The goal is to reach the simplicity of shell 
scripting. 
 
To execute the previous command, one would simple again use 
the go() method: 
 
(stdout, stderr, ret_status) = cmd( "find", ".", 
"-name", "*.cpp" 
).pipe().cmd( "grep", "-i", "toto" ).go() 
 
Here for my suggestion. It might be more appropriate to post it 
to a mailing list, to get more feedback ? 
 
I am sorry, I am very busy now and won't have time to 
implement this myself. 
 
 
 
 

----------------------------------------------------------------------

Comment By: Andrew Gaul (gaul)
Date: 2003-08-19 09:17

Message:
Logged In: YES 
user_id=139865

Yes, it works.  This is also the same behaviour as
os.system.  os.popen2 allows one to pass either a quoted
string or a sequence of strings (pfremy's suggested
behaviour).  It would be nice to have consistent
functionality, and using a sequence would be easier when
providing a list of files to be operated on.  I am willing
to provide a patch if this is the desired functionality.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-07-20 20:03

Message:
Logged In: YES 
user_id=80475

Does it work for you if the filename is quoted:  "thrill 
seeker.txt" ?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=774546&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to