473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to use execfile with argument under windows

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
3 6728
>
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jonathan | last post by:
I'm puzzled by Python's behavior when binding local variables which are introduced within exec() or execfile() statements. First, consider this simple Python program: # main.py def f() : x = 1...
1
by: Bo Jacobsen | last post by:
I have a number of files compiled to bytecode using py_compile.compile(). The .pyc files can be invoked by python directly ($python file.pyc), but "loading" them by execfile just throws an...
8
by: R. Bernstein | last post by:
In doing the extension to the python debugger which I have here: http://sourceforge.net/project/showfiles.php?group_id=61395&package_id=175827 I came across one little thing that it would be nice...
0
by: Slawomir Nowaczyk | last post by:
Hello, When I execfile a file which contains a syntax error, the file becomes locked and stays this way all the way until I exit the interpreter (I am unable to delete it, for example). I have...
2
by: Alex Popescu | last post by:
Hi all! not be present in Py3k. So, I am wondering what will be its replacement? Considering that most probably Py3k will keep eval and exec, this will still be possible (indeed requiring manual...
1
by: Fernando Perez | last post by:
Hi all, I'm finding the following behavior truly puzzling, but before I post a bug report on the site, I'd rather be corrected if I'm just missing somethin obvious. Consider the following...
5
by: George Sakkis | last post by:
I maintain a few configuration files in Python syntax (mainly nested dicts of ints and strings) and use execfile() to read them back to Python. This has been working great; it combines the...
1
by: moijes12 | last post by:
Hi i have 3 python files and i want to execute the files sequentially using the execfile command.Hence ,i have written the following program fileList = for fileName in fileList :...
4
by: TP | last post by:
Hello, I have a script that uses the "optparse" package to parse the command line. For example: $ script.py --help # displays help about script.py Is this possible to call such a script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.