Need help dealing with spaces in NT paths.

T. C. Mits 71351.356 at compuserve.com
Wed Nov 17 07:00:18 CET 1999


A simple example of the difficulty is:

>>> os.system(r'"dir Program Files"')
Bad command or file name
0
>>>


This is run at the root of C: for simplicity.


I also get:

os.popen(r'"dir Program Files"', "r")
Bad command or file name
<open file '"dir program files"', mode 'r'  at 795930>

What does that mean?
----------------------------------------------------------------------------
---------------------------------
Now this is weird.   I created a test.bat file that just has dir %1 in it.

>>> import os
>>> os.execv("test.bat",["program files"])

C:\>dir files

 Volume in drive C is CDRIVE
 Volume Serial Number is 2E50-0FE9
 Directory of C:\

File not found
                      335,601,664 bytes free

C:\>

Looks like it blew the interpreter too.




os.system("dir Program Files")
<maytagrepairman at yahoo.com> wrote in message
news:80sj4q$l7t$1 at nnrp1.deja.com...
> Ok.  This works so far, but to complicate things further I need also to
> pass an argument to the command.  Both the command and the argument are
> full path names with spaces in them.  If I type something like this at
> the DOS prompt:
>
> "my_full_path_cmd_with_spaces" "my_full_path_arg_with_spaces"
>
> it works.
>
> But if I try to do an equivalent such as this in Python
>
> # this next statement is to see what is passed to os.system()
>     print ('\"%s\" \"%s\"' % (cmd,arg))
>
> # this next statement is the call to os.system()
>     os.system('\"%s\" \"%s\"' % (cmd,arg))
>
> I get
>
> The name specified is not recognized as an
> internal or extenal command, operable program or batch file.
>
> Other variations I've tried give the same results.  Any thoughts on
> this one?
>
>
> In article <uogcu93dt.fsf at cs.uu.nl>,
>   piet at cs.uu.nl wrote:
> > >>>>> wheineman <wheinemanNOwhSPAM at uconect.net.invalid> (W) writes:
> >
> > W> Put quotes around the complete path. For example:
> > W> myExec = "C:\\Program Files\\Trash Can\\compactor.exe"
> >
> > You probably mean:
> > myExec = "\"C:\\Program Files\\Trash Can\\compactor.exe\""
> >
> > or easier:
> > myExec = r'"C:\Program Files\Trash Can\compactor.exe"'
> > --
> > Piet van Oostrum <piet at cs.uu.nl>
> > URL: http://www.cs.uu.nl/~piet [PGP]
> > Private email: Piet.van.Oostrum at gironet.nl
> >
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.






More information about the Python-list mailing list