Launch file from Python

J

jocago

Good afternoon from someone who is trying to learn Python.

I would like to launch an app from within a Python script. From the
examples I have found, I should be able to do this with os.system.

I use this:
os.system("xplanet-1.2.0/xplanet.exe -fontsize 24 -label -target earth
-lat 33.65 -lon -84.42 -radius 40 -num_times 1 -tmpdir .")
This is copied directly from the .bat file that launches the xplanet
app. It works there.

and get this:
1

Can someone fill me in? Thanks.
 
K

kyosohma

Good afternoon from someone who is trying to learn Python.

I would like to launch an app from within a Python script. From the
examples I have found, I should be able to do this with os.system.

I use this:
os.system("xplanet-1.2.0/xplanet.exe -fontsize 24 -label -target earth
-lat 33.65 -lon -84.42 -radius 40 -num_times 1 -tmpdir .")
This is copied directly from the .bat file that launches the xplanet
app. It works there.

and get this:
1

Can someone fill me in? Thanks.

That's just the exit status or run status, if I recall correctly. I
think 0 (i.e. False) means it didn't run properly and anything else is
True, or ok. Something like that. Technically speaking, you should
probably switch to using the subprocess module as it is replacing that
os module's functionality: http://www.python.org/doc/2.4/lib/module-subprocess.html

This thread also discusses it somewhat:
http://www.velocityreviews.com/forums/t348777-python-doc-problem-example-ossystem.html

Mike
 
J

jocago

That's just the exit status or run status, if I recall correctly. I
think 0 (i.e. False) means it didn't run properly and anything else is
True, or ok. Something like that. Technically speaking, you should
probably switch to using the subprocess module as it is replacing that
os module's functionality:http://www.python.org/doc/2.4/lib/module-subprocess.html

This thread also discusses it somewhat:http://www.velocityreviews.com/forums/t348777-python-doc-problem-exam...

Mike

The application, however, never runs. I'll give the sub-process a
shot. Thanks.
 
K

kyosohma

The application, however, never runs. I'll give the sub-process a
shot. Thanks.

Well, that's a problem. I suppose the best thing to try is use some
smaller sets of flags and see if they work. Instead of your long
string, try something smaller, like:

subprocess.Popen("xplanet-1.2.0/xplanet.exe -fontsize 24 -label -
target earth", shell=True)

Once you've gotten it to work on a smaller scale, you should be able
to work your way up.

Mike
 
A

Arnau Sanchez

(e-mail address removed) escribió:
That's just the exit status or run status, if I recall correctly. I
think 0 (i.e. False) means it didn't run properly and anything else is
True, or ok. Something like that.

The other way: 0 means "ok" while everything else means error (at least in
UNIX). The reason is clear: there is usually only one way to do things well, but
many to fail :)
Technically speaking, you should
probably switch to using the subprocess module as it is replacing that
os module's functionality: http://www.python.org/doc/2.4/lib/module-subprocess.html

Correct, subprocess replaces low-level os.system, os.popen*, os.spawn*, popen*
functions.
 
K

kyosohma

(e-mail address removed) escribió:


The other way: 0 means "ok" while everything else means error (at least in
UNIX). The reason is clear: there is usually only one way to do things well, but
many to fail :)


Correct, subprocess replaces low-level os.system, os.popen*, os.spawn*, popen*
functions.

Figures...I couldn't find the docs on it though...and I do know that
some Windows programs return goofy numbers in the 1000s that mean it
worked fine. So, in other words, the return value isn't very helpful.

Mike
 
E

Eric_Dexter

Figures...I couldn't find the docs on it though...and I do know that
some Windows programs return goofy numbers in the 1000s that mean it
worked fine. So, in other words, the return value isn't very helpful.

Mike- Hide quoted text -

- Show quoted text -


I had used popen on windows and had to seperate the arguments out..
(example is in my awk module in dex tracker on sourceforge).. What
you did may not work on windows.
 
J

Jorgen Grahn

Good afternoon from someone who is trying to learn Python.

I would like to launch an app from within a Python script. From the
examples I have found, I should be able to do this with os.system.

I use this:
os.system("xplanet-1.2.0/xplanet.exe -fontsize 24 -label -target earth
-lat 33.65 -lon -84.42 -radius 40 -num_times 1 -tmpdir .")
This is copied directly from the .bat file that launches the xplanet
app. It works there.

and get this:
1

That means "error", as others noted.

It is odd that you get no printouts. Had this been on Unix, you'd
either get "file not found" or similar from the shell trying to run
the thing, or something from xplanet itself (only really badly
programs return failure without printing some kind of cause).

Two more comments, assuming you are on Windows (you mention ".bat
files"):

- You use the relative path xplanet-1.2.0/xplanet.exe. That should
require your program to have the parent of xplanet-1.2.0 as current
directory. Did the .bat script change directory first?

- It is unusual to use / as a path separator on Windows --
xplanet-1.2.0\xplanet.exe is more normal. Some parts of Windows
tolerate both, others do not, IIRC. But Python itself should not
care in this case.

/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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top