Calling an exe from Python?

W

will.h.brown

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
 
S

Sam Pointon

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.
 
S

SPE - Stani's Python Editor

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

import os
os.startfile(fileName)

Stani
 
J

Jorgen Grahn

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,268
Messages
2,571,344
Members
48,019
Latest member
Migration_Expert

Latest Threads

Top