Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Launch file from Python

Reply
Thread Tools

Launch file from Python

 
 
jocago@gmail.com
Guest
Posts: n/a
 
      08-08-2007
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.

 
Reply With Quote
 
 
 
 
kyosohma@gmail.com
Guest
Posts: n/a
 
      08-08-2007
On Aug 8, 12:28 pm, (E-Mail Removed) wrote:
> 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/mo...ubprocess.html

This thread also discusses it somewhat:
http://www.velocityreviews.com/forum...-ossystem.html

Mike

 
Reply With Quote
 
 
 
 
jocago
Guest
Posts: n/a
 
      08-08-2007
On Aug 8, 1:36 pm, (E-Mail Removed) wrote:
> On Aug 8, 12:28 pm, (E-Mail Removed) wrote:
>
> > 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/mo...ubprocess.html
>
> This thread also discusses it somewhat:http://www.velocityreviews.com/forum...c-problem-exam...
>
> Mike


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

 
Reply With Quote
 
kyosohma@gmail.com
Guest
Posts: n/a
 
      08-08-2007
On Aug 8, 1:11 pm, jocago <(E-Mail Removed)> wrote:

> 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

 
Reply With Quote
 
Arnau Sanchez
Guest
Posts: n/a
 
      08-08-2007
http://www.velocityreviews.com/forums/(E-Mail 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/mo...ubprocess.html


Correct, subprocess replaces low-level os.system, os.popen*, os.spawn*, popen*
functions.
 
Reply With Quote
 
kyosohma@gmail.com
Guest
Posts: n/a
 
      08-08-2007
On Aug 8, 2:35 pm, Arnau Sanchez <(E-Mail Removed)> wrote:
> (E-Mail 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/mo...ubprocess.html

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

 
Reply With Quote
 
Eric_Dexter@msn.com
Guest
Posts: n/a
 
      08-09-2007
On Aug 8, 2:39 pm, (E-Mail Removed) wrote:
> On Aug 8, 2:35 pm, Arnau Sanchez <(E-Mail Removed)> wrote:
>
>
>
>
>
> > (E-Mail 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/mo...ubprocess.html

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

 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      08-12-2007
On Wed, 08 Aug 2007 10:28:57 -0700, (E-Mail Removed) <(E-Mail Removed)> wrote:
> 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

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
launch a .py file from a batch file CM Python 5 06-23-2009 09:52 PM
Using Python To Launch Python aha Python 4 07-15-2008 08:28 AM
How to launch an application on a remote computer using Python Milon Python 0 04-27-2005 07:13 PM
Why I can't launch python 2.4 final IDLE? AnkyHe Python 2 12-09-2004 12:10 AM
spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2? nushin Python 3 08-07-2003 10:39 PM



Advertisments