how to use execfile with argument under windows

Matimus mccredie at gmail.com
Tue Jan 2 12:47:55 EST 2007


>
> error output
> IOError: [Errno 2] No such file or directory:"filename.exe -type png
> -source sourcearg -file filename.png"

Use 'os.system' not 'execfile'. 'execfile' is for executing other
python scripts, not arbitrary command line.

Try this:

import os
...
...
os.system("filename.exe -type png -source sourcearg -file
filename.png")

> try
> execfile("d:\pathto\filename.exe -type png -source sourcearg -file
> filename.png")
>
> error output
> IOError: [Errno 2] No such file or directory:"d:\pathto\filename.exe
> filename.exe -type png -source sourcearg -file filename.png"

be careful with your '\'s they tend to get interpreted as escape
characters. You can prefix the string with an 'r', double them up or
use forward slashes.

One of the following should work:
r"d:\pathto\filename.exe -type png -source sourcearg -file
filename.png"
"d:\\pathto\\filename.exe -type png -source sourcearg -file
filename.png"
"d:/pathto/filename.exe -type png -source sourcearg -file filename.png"




More information about the Python-list mailing list