Launching command on windows

kyosohma at gmail.com kyosohma at gmail.com
Thu Sep 27 10:20:03 EDT 2007


On Sep 27, 8:17 am, 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 :)



I got it to work using subprocess.Popen

Not sure why it doesn't work with os.system though.

Mike




More information about the Python-list mailing list