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

How to run external program?

P: n/a
Lad
How can I run external program from Python?
I use Python with XP
Thank you for help
LB

Jan 12 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Lad wrote:
How can I run external program from Python?
I use Python with XP
Thank you for help
LB

The subprocess module is what you want for this.

It's got ways of running external executables as separate subprocesses,
and interacting with the subprocess and both its input and output.

Gary Herron

Jan 12 '07 #2

P: n/a
Lad

Gary Herron wrote:
Lad wrote:
How can I run external program from Python?
I use Python with XP
Thank you for help
LB
The subprocess module is what you want for this.

It's got ways of running external executables as separate subprocesses,
and interacting with the subprocess and both its input and output.
Gary ,
Thank you for your reply.
I use os.popen3 but it does not work properly for me all the time.

Here is a part of my Python program
I use an external program ( here mpeg.exe) for converting sourcefile
into targetfile
###########...
....
....
mpeg = "mpeg.exe -i %s codec mp3 -s 320x240 %s" % (sourcefile,
targetfile)
stdin, stdout, stderr = os.popen3(mpeg)
mpegresult = stdout.read()
mpegerrors = stderr.read()
stdin.close(); stdout.close(); stderr.close()
print ffmpegerrors
print ffmpegresult
#########

It works if the sourcefile is small but if it is large( 30MB) it does
NOT work.It hangs or the file is not converted in full.
Any advice how I should change the program?
Thank you.
L.

Jan 12 '07 #3

P: n/a

Lad wrote:
How can I run external program from Python?
I use Python with XP
Thank you for help
A possible way to do this is the following:
Let's say we want to run a program called program.exe from the path
C/Program/Program.exe. We would first need to import the os module and
type the following:

import os #import the os module
path = 'C:/Program/Program.exe' #give the pathname of the external
program as a string
os.system(path) #execute the program from
python using the os module

There are many other ways, but this should work for short pathnames
without spaces.

Jan 12 '07 #4

P: n/a
"Lad" <py****@hope.czescribió en el mensaje
news:11*********************@38g2000cwa.googlegrou ps.com...
mpeg = "mpeg.exe -i %s codec mp3 -s 320x240 %s" % (sourcefile,
targetfile)
stdin, stdout, stderr = os.popen3(mpeg)
mpegresult = stdout.read()
mpegerrors = stderr.read()
stdin.close(); stdout.close(); stderr.close()
print ffmpegerrors
print ffmpegresult
#########

It works if the sourcefile is small but if it is large( 30MB) it does
NOT work.It hangs or the file is not converted in full.
Any advice how I should change the program?
What do you mean by "NOT work"?
Does it "work" if you execute the same line from the command prompt?

--
Gabriel Genellina

Jan 13 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.