how to use execfile with argument under windows

B

baur79

Hi everybody

i need to execute this command line (different source for n times)

filename.exe -type png -source sourcearg -file filename.png


i try with python (python script and filename.exe in same directory)

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

error output
IOError: [Errno 2] No such file or directory:"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"


please help to solve problem
thanks
 
M

Matimus

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"
 
P

Peter Otten

baur79 said:
i need to execute this command line (different source for n times)

filename.exe -type png -source sourcearg -file filename.png
i try with python (python script and filename.exe in same directory)
execfile("filename.exe -type png -source sourcearg -file filename.png")

That does not do what you think it does, see

http://docs.python.org/lib/built-in-funcs.html#l2h-26

You need os.system() or, for more complex applications, the subprocess
module.

Peter
 
B

baur79

os.system() solve my problem

thanks you guys and happy new year

with best wishes from Kazakhstan / Shymkent city / sodbisystems.kz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,270
Messages
2,571,101
Members
48,773
Latest member
Kaybee

Latest Threads

Top