Reputation: 19
In a DOS .exe
program (with no access to source code), the DOS screen says: rate = 60.
(or some other value).
How do I read the output "60" to use as input to an application I'm making in Python or C/C++, other than by reading and typing it (I want to run it dozens of times).
This program runs in Windows XP mode.
Upvotes: 1
Views: 431
Reputation: 59001
You can also invoke the application from your app and store the return value using ShellExecute.
Upvotes: 0
Reputation: 49587
Try Subprocess module to run dos.exe
program from python code.
import shlex
cmdline = "command to execute your exe file"
cmd = shlex.split(cmdline)
output_process = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).communicate()
Upvotes: 1
Reputation: 151137
Use the subprocess
module. There are a few different ways; the most general is to use a Popen
object.
>>> import subprocess
>>> proc = subprocess.Popen(['echo', 'rate = 60'], stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
>>> proc.communicate()
('rate = 60\n', '')
If you're running Python 2.7 or higher, then you could also use subprocess.check_output
.
Upvotes: 5
Reputation: 21241
In python:
import commands
commands.getoutput(cmd)
http://docs.python.org/library/commands.html#commands.getoutput
Upvotes: 2
Reputation: 5456
You can use pipe.
prgm.exe | anotherprogram.exe
Just remember that the anotherprogram will get the whole output of prgm.exe
Upvotes: 0