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

Calling an exe from Python?

P: n/a
Hi!

I'm new to Python and I need to call an executable file from my script.
Is that possible, and if so, how? Thank you!

whb

Oct 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
from subprocess import Popen
proc = Popen('my_programme.exe')

Use proc.communicate(input) to send input to stdin, and get a tuple of
(stdout, stderr) back. If you need the returncode, use proc.poll() or
proc.wait(), depending on if you want it to block or not.

Oct 16 '05 #2

P: n/a
Slightly offtopic, but you can translate any double clicking (*.exe,
*.pdf, *.html, ...) in the Windows Explorer into:

import os
os.startfile(fileName)

Stani
--
SPE - Stani's Python Editor http://pythonide.stani.be

Oct 16 '05 #3

P: n/a
On 16 Oct 2005 15:23:08 -0700, SPE - Stani's Python Editor <sp**********@gmail.com> wrote:
Slightly offtopic, but you can translate any double clicking (*.exe,
*.pdf, *.html, ...) in the Windows Explorer into:

import os
os.startfile(fileName)


That would be Windows-specific, though.

But yes, it's that one, or os.system, or one of the os.popen*, or one of the
os.spawn*, or module subprocess mentioned elsewhere in the thread.
-- Depending on exactly what you want to do.

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Oct 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.