[Patches] [ python-Patches-466451 ] popen fix for multiple quoted arguments
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 01 Oct 2001 15:36:43 -0700
Patches item #466451, was opened at 2001-09-29 17:34
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=466451&group_id=5470
Category: Core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Brian Quinlan (bquinlan)
>Assigned to: Mark Hammond (mhammond)
Summary: popen fix for multiple quoted arguments
Initial Comment:
In a Windows version of Python, try the following:
os.popen('"<path-of-exe" "path-of-arg"'>.read()
cmd.exe will misinterpret the command string because
it strips the first and last quote in the command
string (cmd.exe /? for details).
This patch does a few things:
1. it encloses the command string sent to cmd.exe in
quotes and uses the /S switch
2. if the shell is not command.com or cmd.exe, it
passes the -c switch to the shell (this makes popen
work if the user's shell is bash, sh, etc.)
3. changes the variables s1, s2 and s3 to cmdPath,
completeCmd and cmdArgs
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2001-10-01 15:36
Message:
Logged In: YES
user_id=31435
Assigned to MarkH for further pondering.
I like giving vrbls useful names The rest seems highly
dubious:
+ Catering to non-MS shells ("-c" vs "/C") is a fine idea,
but what about 4DOS or 4NT, or other non-MS shells that
also expect /C? It looks like this patch will kill people
using them.
- It's not backwards compatible regardless of shell (as
Brian pointed out).
- It's surprising to anyone who has read the cmd docs and
expects cmd.exe to work as documented (by MS).
- Since it's unique to Python's popen, a command string
that works for popen() may break if passed to os.system()
instead, and vice versa, and maybe for os.startfile() too.
Other things bug me, but I'll stop there <wink>. The MS
shells are a godawful mess, and it would really be nice to
supply a rational x-platform "virtual shell" syntax (as Tcl
does for its "exec" cmd). Short of that, I'm not sure a
collection of inconsistent and undocumented hacks is
actually progress; as is, Python's behavior is at least
predictable from reading the MS docs and/or playing with C
programs under MSVC.
----------------------------------------------------------------------
Comment By: Brian Quinlan (bquinlan)
Date: 2001-09-30 13:11
Message:
Logged In: YES
user_id=108973
Mark understands the issue; I've already talked to him
about this.
Another thing that I should have noted is that this patch
does NOT ensure backwards compatibility. Any scripts that
manually quote their command strings, to work around this
problem, will break.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-09-30 11:46
Message:
Logged In: YES
user_id=6380
Tim, whaddayathink? Or is this for Mark?
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=466451&group_id=5470