Running os.system from browser

S

Sean Berry

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

Tim Daneliuk

Sean said:
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
 
F

Fuzzyman

Sean Berry said:
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
 
T

Thomas Guettler

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
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top