Run a python script as an exe and run a new process from it

Discussion in 'Python' started by venutaurus539@gmail.com, Feb 26, 2009.

  1. Guest

    Hello all,
    I've a strange requirement where I need to run a python
    script just as we run an exe (by double clicking through windows
    explorer or by typing the script name at command prompt). In that
    process I should be able to execute another python script in such a
    way that, the second script should continue running but the main one
    should terminate without effecting the second one.

    My requirement may be little confusing so please
    get back if you didn't understand what I meant above.


    Thank you,
    Venu.
     
    , Feb 26, 2009
    #1
    1. Advertising

  2. Tim Wintle Guest

    On Thu, 2009-02-26 at 04:55 -0800, wrote:
    > Hello all,
    > I've a strange requirement where I need to run a python
    > script just as we run an exe (by double clicking through windows
    > explorer or by typing the script name at command prompt).

    I don't know how windows deals with this part
    > In that
    > process I should be able to execute another python script in such a
    > way that, the second script should continue running but the main one
    > should terminate without effecting the second one.

    standard daemon behavior I'd have thought

    This shows how you would do it (with lots of comments). Assume this
    should work on Windows.

    http://code.activestate.com/recipes/278731/

    note the two child threads to prevent zombies - may not be needed on
    windows but good to use them anyway.
     
    Tim Wintle, Feb 26, 2009
    #2
    1. Advertising

  3. Guest

    On Feb 26, 6:10 pm, Tim Wintle <> wrote:
    > On Thu, 2009-02-26 at 04:55 -0800, wrote:
    > > Hello all,
    > >            I've a strange requirement where I need to run a python
    > > script just as we run an exe (by double clicking through windows
    > > explorer or by typing the script name at command prompt).

    >
    > I don't know how windows deals with this part>  In that
    > > process I should be able to execute another python script in such a
    > > way that, the second script should continue running but the main one
    > > should terminate without effecting the second one.

    >
    > standard daemon behavior I'd have thought
    >
    > This shows how you would do it (with lots of comments). Assume this
    > should work on Windows.
    >
    > http://code.activestate.com/recipes/278731/
    >
    > note the two child threads to prevent zombies - may not be needed on
    > windows but good to use them anyway.


    Thanks for the reply,
    Being a newbie to python, I am finding it difficult to
    understand the logic even after thorough reading of comments. Is there
    any simpler way where I can just run a python script from the main
    script and exit without disturbing the second one(This will end based
    on some other constraints which can be handled). Or can some one throw
    some light on where should I run the function os.system(" python
    script2.py") from the main one.

    Thank you,
    venu
     
    , Feb 26, 2009
    #3
  4. Guest

    On Feb 26, 7:00 pm, ""
    <> wrote:
    > On Feb 26, 6:10 pm, Tim Wintle <> wrote:
    >
    >
    >
    > > On Thu, 2009-02-26 at 04:55 -0800, wrote:
    > > > Hello all,
    > > >            I've a strange requirement where I need to run a python
    > > > script just as we run an exe (by double clicking through windows
    > > > explorer or by typing the script name at command prompt).

    >
    > > I don't know how windows deals with this part>  In that
    > > > process I should be able to execute another python script in such a
    > > > way that, the second script should continue running but the main one
    > > > should terminate without effecting the second one.

    >
    > > standard daemon behavior I'd have thought

    >
    > > This shows how you would do it (with lots of comments). Assume this
    > > should work on Windows.

    >
    > >http://code.activestate.com/recipes/278731/

    >
    > > note the two child threads to prevent zombies - may not be needed on
    > > windows but good to use them anyway.

    >
    > Thanks for the reply,
    >            Being a newbie to python, I am finding it difficult to
    > understand the logic even after thorough reading of comments. Is there
    > any simpler way where I can just run a python script from the main
    > script and exit without disturbing the second one(This will end based
    > on some other constraints which can be handled). Or can some one throw
    > some light on where should I run the function os.system(" python
    > script2.py") from the main one.
    >
    > Thank you,
    > venu


    Adding to the above.. I've to do it in Windows platform and what I can
    see from the illustration (/dev/null) etc. they are for Unix
    Environment.

    Thank you,
    Venu
     
    , Feb 26, 2009
    #4
  5. Tim Wintle Guest

    On Thu, 2009-02-26 at 06:00 -0800, wrote:
    > Thanks for the reply,
    > Being a newbie to python, I am finding it difficult to
    > understand the logic even after thorough reading of comments. Is there
    > any simpler way where I can just run a python script from the main
    > script and exit without disturbing the second one(This will end based
    > on some other constraints which can be handled). Or can some one throw
    > some light on where should I run the function os.system(" python
    > script2.py") from the main one.


    That would be a simple way of doing it :)
     
    Tim Wintle, Feb 26, 2009
    #5
  6. Guest

    On Feb 26, 7:47 pm, Tim Wintle <> wrote:
    > On Thu, 2009-02-26 at 06:00 -0800, wrote:
    > > Thanks for the reply,
    > >            Being a newbie to python, I am finding it difficult to
    > > understand the logic even after thorough reading of comments. Is there
    > > any simpler way where I can just run a python script from the main
    > > script and exit without disturbing the second one(This will end based
    > > on some other constraints which can be handled). Or can some one throw
    > > some light on where should I run the function os.system(" python
    > > script2.py") from the main one.

    >
    > That would be a simple way of doing it :)


    When I run that script on Windows it fails throwing the below error:

    AttributeError: 'module' object has no attribute 'fork'

    Please help me out..
     
    , Feb 26, 2009
    #6
  7. En Thu, 26 Feb 2009 13:32:27 -0200,
    <> escribió:

    > On Feb 26, 7:47 pm, Tim Wintle <> wrote:
    >> On Thu, 2009-02-26 at 06:00 -0800, wrote:
    >> > Thanks for the reply,
    >> >            Being a newbie to python, I am finding it difficult to
    >> > understand the logic even after thorough reading of comments. Is there
    >> > any simpler way where I can just run a python script from the main
    >> > script and exit without disturbing the second one(This will end based
    >> > on some other constraints which can be handled). Or can some one throw
    >> > some light on where should I run the function os.system(" python
    >> > script2.py") from the main one.

    >>
    >> That would be a simple way of doing it :)

    >
    > When I run that script on Windows it fails throwing the below error:
    >
    > AttributeError: 'module' object has no attribute 'fork'
    >
    > Please help me out..


    Unless you have any special needs, just stick to os.system("...")

    --
    Gabriel Genellina
     
    Gabriel Genellina, Feb 26, 2009
    #7
  8. Try this as an outline:
    #### script1.py
    from subprocess import Popen

    if __name__ == '__main__':
    scriptname = "script2.py"

    Popen("python %s" % scriptname, shell=True)


    print "I'm done"


    #### script2.py
    from time import sleep

    if __name__ == '__main__':
    while (True):
    print "waiting.."
    sleep(2)

    ###########################
    If you install python using the Windows Installer (.exe), it should
    set up .py files to be opened by python when double-clicking on them.
    Alternatively, you can right-click on your .py file and go to "Open
    With..." then "choose program", then click "Browse...", you can Browse
    to the python executable, so Explorer will use it to open .py files
    when you double-click on them.

    As someone else mentioned there is also a py2exe program. Google it.

    2009/2/26 <>:
    > Hello all,
    >           I've a strange requirement where I need to run a python
    > script just as we run an exe (by double clicking through windows
    > explorer or by typing the script name at command prompt). In that
    > process I should be able to execute another python script in such a
    > way that, the second script should continue running but the main one
    > should terminate without effecting the second one.
    >
    >                    My requirement may be little confusing so please
    > get back if you didn't understand what I meant above.
    >
    >
    > Thank you,
    > Venu.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >




    --
    "Ray, when someone asks you if you're a god, you say YES!"
     
    Paddy O'Loughlin, Feb 26, 2009
    #8
  9. Guest

    On Feb 26, 11:14 pm, "Paddy O'Loughlin" <>
    wrote:
    > Try this as an outline:
    > #### script1.py
    > from subprocess import Popen
    >
    > if __name__ == '__main__':
    >         scriptname = "script2.py"
    >
    >         Popen("python %s" % scriptname, shell=True)
    >
    >         print "I'm done"
    >
    > #### script2.py
    > from time import sleep
    >
    > if __name__ == '__main__':
    >     while (True):
    >         print "waiting.."
    >         sleep(2)
    >
    > ###########################
    > If you install python using the Windows Installer (.exe), it should
    > set up .py files to be opened by python when double-clicking on them.
    > Alternatively, you can right-click on your .py file and go to "Open
    > With..." then "choose program", then click "Browse...", you can Browse
    > to the python executable, so Explorer will use it to open .py files
    > when you double-click on them.
    >
    > As someone else mentioned there is also a py2exe program. Google it.
    >
    > 2009/2/26 <>:
    >
    >
    >
    > > Hello all,
    > >           I've a strange requirement where I need to run a python
    > > script just as we run an exe (by double clicking through windows
    > > explorer or by typing the script name at command prompt). In that
    > > process I should be able to execute another python script in such a
    > > way that, the second script should continue running but the main one
    > > should terminate without effecting the second one.

    >
    > >                    My requirement may be little confusing so please
    > > get back if you didn't understand what I meant above.

    >
    > > Thank you,
    > > Venu.
    > > --
    > >http://mail.python.org/mailman/listinfo/python-list

    >
    > --
    > "Ray, when someone asks you if you're a god, you say YES!"


    Thanks for the reply,,
    I am trying to use the above application using psexec()in
    command line.But it failed returning the error message

    exited with error code 255.

    But when I ran the application normally it worked
    fine.Do I need to add anything to my python script(either the main one
    or the script which is calling it) to make it work.

    Thank you,
    Venu Madhav.
     
    , Feb 27, 2009
    #9
  10. 2009/2/27 <>:
    > Thanks for the reply,,
    >            I am trying to use the above application using psexec()in
    > command line.But it failed returning the error message
    >
    >  exited with error code 255.
    >
    >              But when I ran the application normally it worked
    > fine.Do I need to add anything to my python script(either the main one
    > or the script which is calling it) to make it work.


    I don't have any experience with psexec, so I'm not sure if I can help
    you with that.
    I assume this means that you are trying to run the script on a remote
    computer? (Elsewise, why use psexec?)

    I took a look at it though and it seems that it always exits with
    *some* error code. I think it's more usual for that error code to be
    zero, though (it does when I run it on my machine).

    You might try "psexec start script1.py", which might work if you've
    successfully set Explorer to run .py files with python.exe when you
    double-click on them.

    "psexec python script1.py" will work if the python.exe is in the correct path.

    You can also specify the full path to your python.exe. if you know it
    e.g.: "psexec C:\python25\python.exe script1.py"



    --
    "Ray, when someone asks you if you're a god, you say YES!"
     
    Paddy O'Loughlin, Feb 27, 2009
    #10
    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. Robert W. Eckert
    Replies:
    4
    Views:
    796
    =?Utf-8?B?Um9iIEVja2VydA==?=
    Oct 5, 2004
  2. Metalone
    Replies:
    5
    Views:
    288
    Thomas Heller
    Oct 19, 2007
  3. franckspike
    Replies:
    1
    Views:
    334
    Boris
    Jul 3, 2008
  4. daved170

    run exe and create exe

    daved170, Oct 11, 2009, in forum: Python
    Replies:
    3
    Views:
    483
    Benjamin Kaplan
    Oct 11, 2009
  5. Sangeeta Huddar
    Replies:
    1
    Views:
    137
    Sangeeta Huddar
    Feb 27, 2009
Loading...

Share This Page