[python-win32] os.system problem

Magnus Lyckå magnus at thinkware.se
Fri May 9 00:43:50 EDT 2003


At 10:53 2003-05-07 -0700, Lawrence W. Leung wrote:
>Hi,
>
>I'm trying to use os.system to execute a command in win2k with python
>2.2.2 and it's not behaving as expected.  Basically, the idea is I pass it
>a command line that begins with a quoted path to an executable (to avoid
>the problem of the space in the path) and also a quoted argument and it
>fails to find the executable.  But oddly enough when I unquote the
>argument it seems to find the executable just fine.

Doesn't the same thing happen if you run these things directly
from the command line?

It's my experience in Windows that I have to remove quotes that
I would be using if I was in Unix. In Unix, the shell will remove
the quotes before calling commands. The quotes will determine if
a parameter is just one parameter, despite containing spaces etc,
and single quotes will stop expansion of $ etc, but Windows don't
have these things. Whatever you type at the command line will be
thrown at your program, quotes and all. Unix utilities won't expect
that.

Another thing you might try is to replace os.system with popen2.popen3
like this:

 >>> import popen2
 >>> out, inp, err = popen2.popen3('my command')
 >>> inp.close()
 >>> out.read()
[output from my command]
 >>> err.read()
[error from command]

That might provide more hints than the exit codes...


--
Magnus Lycka (It's really Lyckå), magnus at thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program 




More information about the Python-win32 mailing list