Launch file from Python

Discussion in 'Python' started by jocago@gmail.com, Aug 8, 2007.

  1. Guest

    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.
    , Aug 8, 2007
    #1
    1. Advertising

  2. Guest

    On Aug 8, 12:28 pm, 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/module-subprocess.html

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

    Mike
    , Aug 8, 2007
    #2
    1. Advertising

  3. jocago Guest

    On Aug 8, 1:36 pm, wrote:
    > On Aug 8, 12:28 pm, 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/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.
    jocago, Aug 8, 2007
    #3
  4. Guest

    On Aug 8, 1:11 pm, jocago <> 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
    , Aug 8, 2007
    #4
  5. 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.
    Arnau Sanchez, Aug 8, 2007
    #5
  6. Guest

    On Aug 8, 2:35 pm, Arnau Sanchez <> wrote:
    > 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.


    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
    , Aug 8, 2007
    #6
  7. Guest

    On Aug 8, 2:39 pm, wrote:
    > On Aug 8, 2:35 pm, Arnau Sanchez <> wrote:
    >
    >
    >
    >
    >
    > > 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.

    >
    > 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.
    , Aug 9, 2007
    #7
  8. Jorgen Grahn Guest

    On Wed, 08 Aug 2007 10:28:57 -0700, <> 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!
    Jorgen Grahn, Aug 12, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr Gordonz

    Button to launch "Open File" Dialogue

    Mr Gordonz, Aug 15, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    2,798
    Mr Gordonz
    Aug 21, 2003
  2. Microsoft
    Replies:
    6
    Views:
    506
    Microsoft
    Apr 28, 2005
  3. Tomas
    Replies:
    3
    Views:
    330
    Roedy Green
    Sep 24, 2003
  4. aha
    Replies:
    4
    Views:
    238
    Gabriel Genellina
    Jul 15, 2008
  5. CM
    Replies:
    5
    Views:
    1,477
    Dave Angel
    Jun 23, 2009
Loading...

Share This Page