473,408 Members | 1,771 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,408 software developers and data experts.

Run program from within Python

Greetings all...

Newbie to Python... need help with opening a file from within
Python... see the following code.
import popen2
stdout, stdin = popen2.popen2('c:\test\OpenProgram.exe 1 1')
keygen = stdout.read()
print "The keygen value is: %s" % keygen
from the command line if I execute "OpenProgram.exe 1 1" a number is
returned. ("1 1" are required to return the value needed.) Ultimately
I want to take that number and apply it to another script, but the
program is not running.

Suggestions?
NEWBIE to Python..
Aug 6 '08 #1
3 1999
On Aug 6, 2:42*pm, frankrentef <frankren...@yahoo.comwrote:
Greetings all...

Newbie to Python... need help with opening a file from within
Python... see the following code.

import popen2
stdout, stdin = popen2.popen2('c:\test\OpenProgram.exe 1 1')
keygen = stdout.read()
print "The keygen value is: %s" % keygen

from the command line if I execute "OpenProgram.exe 1 1" a number is
returned. *("1 1" are required to return the value needed.) Ultimately
I want to take that number and apply it to another script, but the
program is not running.

Suggestions?

NEWBIE to Python..
If you're using Python 2.4+, popen2 is deprecated. I recommend reading
up on the subprocess module instead. Here's a couple links:

http://blog.doughellmann.com/2007/07...ubprocess.html
http://docs.python.org/lib/module-subprocess.html

The first one also explains how to communicate with a process you
opened.

Mike
Aug 6 '08 #2
On Aug 6, 3:42*pm, frankrentef <frankren...@yahoo.comwrote:
stdout, stdin = popen2.popen2('c:\test\OpenProgram.exe 1 1')
What Mike said about subprocess.

Also, in regular Python strings, \t means a tab character. You need
to replace \ with \\ in the programme path ('c:\\test\\OpenProgram.exe
1 1') or use a raw string (r'c:\test\OpenProgram.exe 1 1'). (The r
informs the Python parser that backslashes are to be used veratim, not
as special code. If you're using Windows, raw strings make for fewer
headaches when dealing with file paths.)

Geoff G-T

Aug 6 '08 #3
THNX for the links... lotta reading for the newbie!
Aug 6 '08 #4

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

Similar topics

0
by: Tim Fuehner | last post by:
Dear Newsgroup, I have a problem that is somewhat related to Alexandre Gillet's ones: "build a static python executable". I would like to make a C program scriptable. Therefor, I have included...
15
by: Aubrey Hutchison | last post by:
### this will test if your version of IDLE on windows is a MATURE program design ### print "Hello world, If Python IDLE is a mature program design it will output this" Save this simple...
7
by: Derek W | last post by:
Hello all, I have a few questions about the best way to organize a large Python program. This would be a large program with a GUI interface, too large to be put all in one script file by any...
44
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
0
by: Praveen, Tayal (IE10) | last post by:
Hi Guys, I am having problems in the following C API program where myOtim_system is callable from python function. The module is listed below - static PyObject * myOptim_system(PyObject...
1
by: dfaber | last post by:
Aloha! I want to terminate a process/program from within a python script. For example, if I have a program say foo.sh that starts running, then I can run it from within a python script using...
2
by: Graham Menhennitt | last post by:
I have a large Python 2.5 program that I want my users to be able to "extend" using a Python script. However, I want their script to run in a sandbox within the overall program so that they only...
0
by: Chico Jayanthan | last post by:
Hi, I call an external windows program (.exe) from a python script. Something like os.system('test.exe'). I want to set a timeout for the external windows program to return. If no results are...
14
by: jmDesktop | last post by:
Hi, I'm trying to learn Python. I using Aquamac an emac implementation with mac os x. I have a program. If I go to the command prompt and type pythong myprog.py, it works. Can the program be...
4
by: DG | last post by:
Alright, I have searched and searched and read many conversations on the topic of relative and absolute imports and am still not getting the whole thing through my skull. Highlights of what I've...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...

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.