Running os.system from browser

Discussion in 'Python' started by Sean Berry, Jul 13, 2004.

  1. Sean Berry

    Sean Berry Guest

    I have a python program that I want to
    be able to run from a browser window.

    It gets run in a cron job every day, but
    I want my boss to be able to run it whenever
    he wants to since the database it uses is
    updated many times throughout the day.

    I have the following as the first few lines
    of a program.

    #!/usr/local/bin/python
    import os
    os.system('/path/to/my/program.py')
    print "Content-Type: text/html\n"

    The rest of the program just spits out some
    simple html. Ths os.system call is what is
    breaking the program when I run it from a
    browser, because I have commented it out
    and the program works.

    The program also works from the command
    line. How can I fix this problem?

    Thanks for any help.
    Sean Berry, Jul 13, 2004
    #1
    1. Advertising

  2. Sean Berry

    Tim Daneliuk Guest

    Sean Berry wrote:

    > I have a python program that I want to
    > be able to run from a browser window.
    >
    > It gets run in a cron job every day, but
    > I want my boss to be able to run it whenever
    > he wants to since the database it uses is
    > updated many times throughout the day.
    >
    > I have the following as the first few lines
    > of a program.
    >
    > #!/usr/local/bin/python
    > import os
    > os.system('/path/to/my/program.py')
    > print "Content-Type: text/html\n"
    >
    > The rest of the program just spits out some
    > simple html. Ths os.system call is what is
    > breaking the program when I run it from a
    > browser, because I have commented it out
    > and the program works.
    >
    > The program also works from the command
    > line. How can I fix this problem?
    >
    > Thanks for any help.
    >
    >


    At first glance, this suggests itself:


    os.system('/path/to/python /path/to/my/program.py')

    I
    --
    ----------------------------------------------------------------------------
    Tim Daneliuk
    PGP Key: http://www.tundraware.com/PGP/
    Tim Daneliuk, Jul 13, 2004
    #2
    1. Advertising

  3. Sean Berry

    Fuzzyman Guest

    "Sean Berry" <> wrote in message news:<jRGIc.5063$%w5.1899@okepread05>...
    > I have a python program that I want to
    > be able to run from a browser window.
    >
    > It gets run in a cron job every day, but
    > I want my boss to be able to run it whenever
    > he wants to since the database it uses is
    > updated many times throughout the day.
    >
    > I have the following as the first few lines
    > of a program.
    >
    > #!/usr/local/bin/python
    > import os
    > os.system('/path/to/my/program.py')
    > print "Content-Type: text/html\n"
    >
    > The rest of the program just spits out some
    > simple html. Ths os.system call is what is
    > breaking the program when I run it from a
    > browser, because I have commented it out
    > and the program works.
    >
    > The program also works from the command
    > line. How can I fix this problem?
    >
    > Thanks for any help.


    I recently wrote a CGI that executes shell commands retrieved from a
    HTML form.
    It would fail (the dreaded internal error 500) when I used os.system
    - but would work fine if I used os.popen2
    It's likely that something similar is happening... although perhaps
    someone more server savvy could confirm/explain.

    Regards,

    Fuzzy

    http://www.voidspace.org.uk/atlantibots/pythonutils.html
    Fuzzyman, Jul 13, 2004
    #3
  4. Am Mon, 12 Jul 2004 18:25:07 -0700 schrieb Sean Berry:

    > I have a python program that I want to
    > be able to run from a browser window.


    > I have the following as the first few lines
    > of a program.
    >
    > #!/usr/local/bin/python
    > import os
    > os.system('/path/to/my/program.py')
    > print "Content-Type: text/html\n"


    > The program also works from the command
    > line. How can I fix this problem?


    os.system() writes to stdout. This means if your
    programm.py write to stdout it is send to the browser.

    Use os.system('.. >> logfile 2>&1') or popen4

    HTH,
    Thomas

    --
    Thomas G├╝ttler, http://www.thomas-guettler.de/
    Thomas Guettler, Jul 13, 2004
    #4
    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. Magnus Gran-Jansen

    Running a C# program w/GUI through a web browser

    Magnus Gran-Jansen, May 10, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    423
    Magnus Gran-Jansen
    May 10, 2005
  2. Peter Bradley
    Replies:
    2
    Views:
    334
    Kevin Spencer
    Jul 16, 2003
  3. KatB
    Replies:
    1
    Views:
    347
    Bob Lehmann
    Oct 24, 2003
  4. Anonieko Ramos
    Replies:
    0
    Views:
    536
    Anonieko Ramos
    Apr 14, 2004
  5. Benjamin Rutt
    Replies:
    2
    Views:
    934
    Peter Hansen
    Dec 20, 2005
Loading...

Share This Page