Launching command on windows

mauro mauro.tiz at gmail.com
Thu Sep 27 10:16:45 EDT 2007


On 27 Set, 15:17, Alexandre Badez <alexandre.ba... at gmail.com> wrote:
> Hy,
>
> I'm working on windows and I try to do something like:
>
> import os
> APP = os.path.abspath("C:\\Program Files\\Notepad++\\notepad++.exe")
> FILE1 = os.path.abspath("D:\\Documents and settings\\test1.py")
> FILE2 = os.path.abspath("D:\\Documents and settings\\test2.py")
> command = '"%(app)s" "%(file1)s" "%(file2)s"' % {
>     'app' : APP,
>     'file1' : FILE1,
>     'file2' : FILE2}
> # === FOR 'DEBUG' ===
> print APP
> print FILE1
> print FILE2
> print command
> print repr(command)
> # === END FOR 'DEBUG' ===
> os.system(command)
>
> This code give in output:
> C:\Program Files\Notepad++\notepad++.exe
> D:\Documents and settings\test1.py
> D:\Documents and settings\test2.py
> "C:\Program Files\Notepad++\notepad++.exe" "D:\Documents and settings
> \test1.py" "D:\Documents and settings\test2.py"
> '"C:\\Program Files\\Notepad++\\notepad++.exe" "D:\\Documents and
> settings\\test1.py" "D:\\Documents and settings\\test2.py"'
>
> 'C:\Program' n'est pas reconnu en tant que commande interne
> ou externe, un programme ex,cutable ou un fichier de commandes.
> # <= My windows is a french one
> # This error message could be translated as:
> # 'c:\Program' is not an internal nor external command, an executable
> program nor a command file
>
> But if I copy the command in the output, an paste it in a console, it
> work very well.
> Does any of you know what I can do ?
>
> PS: I think I'm oblige to add " neer every path for spaces in path,
> but if you know an other way, it could be cool :)

If you don't mind using spawnl instead of system, this should work
even with spaces:
os.spawnl(os.P_NOWAITO, command)
I hope it helps.

Mauro




More information about the Python-list mailing list