problem with os.system calls under win32

Kevin Cazabon kcazabon at home.com
Sat Apr 15 01:48:31 EDT 2000


If you want it to be even more bullet-proof, use the Win32 call for
GetShortPathName, and don't worry about it.

>>> import win32api
>>> print win32api.GetShortPathName('c:\\f o o\\bar.exe')
c:\FOO~1\BAR.EXE

q:]


Kevin.

"Gresh" <gresham at mediavisual.com> wrote in message
news:8d7o4d$c8h1 at imsp212.netvigator.com...
> Actually I was trying a similar thing, and decided to be smart and use
> os.path.join
> but this is what happened:
>
> >>> import os
> >>> os.system(os.path.join("D:","My Documents","test.bat"))
> 'D:\My' is not recognized as an internal or external command,
> operable program or batch file.
> 1
>
> However:
> >>> os.path.exists(os.path.join("D:","My Documents","test.bat"))
> 1
>
> That's a bit confusing !
>
> Of course from Gordon's example:
> >>> os.system('"%s"' % (os.path.join("D:","My Documents","test.bat")))
> 0
>
> works
>
> Regards,
> Paul
>
>
> "Gordon McMillan" <gmcm at hypernet.com> wrote in message
> news:1256392132-57146878 at hypernet.com...
> > william_93402 at my-deja.com wrote:
> >
> > > I am attempting to do a system call in a directory with spaces in the
> > > name. For example:
> > >
> > > >>>import os
> > > >>>os.system('c:\\f o o\\bar.exe')
> > > 1
> > >
> > > when I place the executable in a dir such as c:\\foo I can
successfully
> > > execute the system call. Is there something special I have to do when
> > > directory names contain spaces? Just for notes I am running by example
> > > in build 125 of pythonwin.
> >
> > Follow MS's rules:
> > os.system('"c:\\f o o\\bar.exe"')
> >
> > (must be double-quotes).
> >
> > - Gordon
> >
>
>





More information about the Python-list mailing list