473,654 Members | 3,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running a DOS exe file from python

I would like to execute a windows program from python and wait for it
to finish before returning to the python script.

The script I want to run has a set number of arguments.

The following does work fine:
os.system(r"c:\ tmp\myprog.exe arg1 arg2 arg3")

The problem I have is that the path to myprog.exe and the arguments are
variable so I need to pass them in as arguments to myprog.exe.

Thanks

Jan 26 '06 #1
3 1408
I posted this earlier on yahoo groups and then realized that the most
recent post was 2003. What I didn't realize is that it posted to this
group so I posted it again.

The other post is:
http://groups.google.com/group/comp....05733f4a83399f

Jan 26 '06 #2
Hello,

Something like this:
progname = 'c:\tmp\myprog. exe arg1 '+'-- help'
os.system(r'pro gname)

should work too.
So you should be able to change progname to any location you need to
start it and all the args to whatever is needed.

Jan 27 '06 #3
Rinzwind wrote:
Something like this:
progname = 'c:\tmp\myprog. exe arg1 '+'-- help'
os.system(r'pro gname)


Well, other than the ways in which it wouldn't work:

1. "arg1" doesn't get substituted with anything, if that's what you
meant, but rather is inserted as the literal string "arg1". If you
meant that just as an example of some other argument that would be
hardcoded, then it's unclear why you have the + in there since you could
just have written the whole thing as a single string.

2. You need the 'r' meaning raw string *on the string literal*, in the
first line, not in the second line. In your code, the string bound to
the name "progname" contains an ASCII TAB character in the third byte,
after the "c" and the ":", which isn't likely what you wanted.

3. In the second line you have an unterminated string...

Jan 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5310
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of these files, I wish to do the same using another python code instead of running each of these files one by one, which would be cumbersome giving the argv of each file every single time. This can be easily done using a shell script but I just...
8
2050
by: rbt | last post by:
Is there a recommended or 'Best Practices' way of checking the version of python before running scripts? I have scripts that use the os.walk() feature (introduced in 2.3) and users running 2.2 who get errors. Instead of telling them, 'Upgrade you Python Install, I'd like to use sys.version or some other way of checking before running. Whatever I do, I need it to work on Linux, Mac and Windows. I thought of sys.version... but getting...
3
3674
by: Fabio Pliger | last post by:
Hi, is it possibile, in python, to check for an already running instance of an application? My problem is that, if my program i running and the user relaunch it, i don't want to open a new instance and have to instances of the same program running togheter... Can someone help me on this? Fabio P.
1
1693
by: sub1ime_uk | last post by:
I apologise if this is a well known problem. I've searched and can't find a clear description or fix. Hope someone can help. I am running my Python scripts under Windows 2000 using Python 2.4 Build 243 from Activestate. If I want to specify a file as standard input to my script I can just enter a command like: H:\> pyscript.py file.inp
7
4031
by: iclinux | last post by:
Environment: WinXP SP2 + Python 2.4.2, with SOAPpy-0.11.6.zip, fpconst-0.7.2.zip, and PyXML-0.8.4.win32-py2.4.exe installed. Problem: I'm reading DiveIntoPython these days. When running code of "Example 12.11. Calling A Web Service Through A WSDL Proxy", I got some errors as follow. Will you please give me some suggestion? IDLE 1.1.2's Output:
4
1827
by: Michael Malinowski | last post by:
Is there a way to read the directory that the currently running python file is located in? Cheers Mike.
8
2768
by: geert | last post by:
Hi all, I have a mac mini running maocosx 10.5 leopard I want to deploy a django project on. My backend is MySQL, and I have it running as a 64- bit app. Of course, apache2 is also running as 64-bit. MySQLdb installs with the usual warnings after applying the various patches I found here and there. These patches consist of altering _mysql.c and site.cfg.
7
2182
by: alito | last post by:
Hi all, I am new to using packages to group my modules. I can't figure out how to run a module that uses relative imports without writing a wrapper that imports that module. Everything I try it complains that I am attempting a relative import in a non-package. eg ~/python/testpackage$ ls config.py importer.py __init__.py
0
1591
by: eddiefisher41 | last post by:
Hey guys. Im having problems running a python cgi. Im using the example code from: http://www.python.org/doc/essays/ppt/sd99east/sld041.htm as writen by Van Rossum himself I can get the script to run the python script but all that happens is that the black python box appears then disapears, the html that the python scripts should generate is never output. My html is: <html><head> <meta http-equiv="Content-Type" content="text/html;...
5
2538
by: Christopher Brewster | last post by:
I am running the same script on the same data on two different machines (the folder is synchronised with Dropbox). I get two different results. All the script does is count words in different files and perform a simple set operation on the word lists. The laptop is a Macbook Pro (2 1/2 years old) running OS X 10.5.5 with Python 2.5.1 The desktop is an iMac (brand new) running OS X 10.5.5 also with Python 2.5.1 I have tried running the...
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8708
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7307
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.