By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

how to use execfile with argument under windows

P: n/a
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

Jan 2 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
>
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"

Jan 2 '07 #2

P: n/a
baur79 wrote:
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
Jan 2 '07 #3

P: n/a
os.system() solve my problem

thanks you guys and happy new year

with best wishes from Kazakhstan / Shymkent city / sodbisystems.kz
On Jan 2, 11:49 pm, Peter Otten <__pete...@web.dewrote:
baur79 wrote:
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
Jan 3 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.