FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Python execute External Application. How?





hack_man_
What is the command and syntax to make a Python script to run an external application?

I want to create a script, where you are given options and one of them is to launch an external .mdb MS Access file. But I need to find out what the command is.
MrBlueSky
Use the system command, for example:

Code:

os.system("ls -l")


If you want to capture the output from the external program you run, use popen

for example:

Code:

result = os.popen("ls", "r").read()
hack_man_
MrBlueSky wrote:
Use the system command, for example:

Code:

os.system("ls -l")


Right, thank you. Where does the file location go in there? What would the command be if the file was at, say:
Code:
C:\WINDOWS\system32\mspaint.exe"


Is the "-l" like an operator. Like adding "-w" onto the end of the shortcut for The Sims 2 makes it run windowed? Or is it just part of the command?
MrBlueSky
hack_man_ wrote:
MrBlueSky wrote:
Use the system command, for example:

Code:

os.system("ls -l")


Right, thank you. Where does the file location go in there? What would the command be if the file was at, say:
Code:
C:\WINDOWS\system32\mspaint.exe"


Is the "-l" like an operator. Like adding "-w" onto the end of the shortcut for The Sims 2 makes it run windowed? Or is it just part of the command?


I'm no sure, but I think on windows you can use:

"C:\WINDOWS\system32\mspaint.exe"

if that doesn't work, try:

Code:
C:/WINDOWS/system32/mspaint.exe"


The "-l" is not an operator, but an option to ls, so you can use something like

Code:

os.system("sim2 -w")


to run sims 2 in a window.
deepak
popen2 is much better than popen .. in both cases popen and os .. it doesnt wait for the process .. if you wish to hold or timeout your command then check it out "subprocess" and "win32api"

Both poen2 and os module exactly is same fashion like COMMAND PROMT / SHELL does. so if you wish to execute any command from your python program then use:

os.system(my_command) // it return 0 or 1 .. 1 on failure
(stdout, stderr) = popen2.popen3(my_command)

stdout.read() // console output
stderr.read() // error output

my_command can be any internal/external DOS COMMAND/ SHELL COMMAND.
Related topics
P2P Puzzle
Fortran Tutorials(77)
PHP Problem: Unable to execute ext. commands
Review: GNOME 2.14 (from Linux.com)
PHP VS ASP
What are your Firefox extensions
A Simple Python Dynamic Page
.: User login systems for your site :. CHEAP AND EASY!
The Bootloader about execute program in SRAM
help: some function php is off
exec() allowed? What is this...
Python Web Application Framework
How to create an Python application with frihost?
A Python Expression Evaluator
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.