By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,709 Members | 1,603 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,709 IT Pros & Developers. It's quick & easy.

Strange behavior with os call in cgi script

P: n/a
I have written a cgi script that seems to run perfectly from the
command line when I simulate some cgi input using
os.environ['QUERY_STRING'].

The thing is that when I run it from the browser, one of my os.system
calls, which gets excecuted fine when running the program in the
interpreter, doesn't seem to get excecuted, or gets excecuted but does
nothing.

Does anyone know whats going on or how I could debug this problem?

It is worth noting that other os.system calls in the script get
excecuted fine.

Feb 5 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
sophie_newbie schrieb:
I have written a cgi script that seems to run perfectly from the
command line when I simulate some cgi input using
os.environ['QUERY_STRING'].

The thing is that when I run it from the browser, one of my os.system
calls, which gets excecuted fine when running the program in the
interpreter, doesn't seem to get excecuted, or gets excecuted but does
nothing.

Does anyone know whats going on or how I could debug this problem?
[...]


Probably the environment is different when your program is executed by
your web server. So either PATH is wrong and your program is not found
or some other environment variable is wrong and you could debug it by
printing the environment in your program.
Feb 5 '06 #2

P: n/a
OK, interesting, but just how dow I print he environment in the
program??

Feb 5 '06 #3

P: n/a
sophie_newbie:
OK, interesting, but just how dow I print he environment in the
program??


Add logging to your program:
http://www.python.org/doc/2.3.5/lib/module-logging.html

And log the environment:
http://www.python.org/dev/doc/newsty...-procinfo.html

--
René Pijlman
Feb 5 '06 #4

P: n/a
Rene Pijlman wrote:
sophie_newbie:
OK, interesting, but just how dow I print he environment in the
program??

Add logging to your program:
http://www.python.org/doc/2.3.5/lib/module-logging.html

Probably oiverkill, particularly for a beginner (is it only me that
thinks the logging module is either way over-complicated or way
under-documented?).
And log the environment:
http://www.python.org/dev/doc/newsty...-procinfo.html


regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Feb 6 '06 #5

P: n/a
Steve Holden wrote:
Add logging to your program:
http://www.python.org/doc/2.3.5/lib/module-logging.html

Probably oiverkill, particularly for a beginner (is it only me that
thinks the logging module is either way over-complicated or way
under-documented?).


No, I would agree with you on that. I get the impression that it was
designed by studying some pre-existing logging packages and saying 'what
neat features can we take from each of these' rather than by writing up a
set of use-cases and saying 'what is the simplest way we can make all of
these possible'.

The way it is now means there is quite a step from the simplest possible
use to slightly more complex use. For example, the support for reading
configuration files is wonderfully general purpose, but far too much for
the vast majority of applications: you really don't want to expose a
typical end user to that sort of configuration soup. If all you want in
your application is to let the user specify the name of the logfile and the
logging level you are on your own (and you can't even convert the log level
name from a string to the required number without accessing an _ prefixed
variable in the logging module).

Feb 6 '06 #6

P: n/a
Steve Holden:
Rene Pijlman:
Add logging to your program:
http://www.python.org/doc/2.3.5/lib/module-logging.html

Probably oiverkill, particularly for a beginner (is it only me that
thinks the logging module is either way over-complicated or way
under-documented?).


It struck me as somewhat complicated as well.

Looking at the basic example:
http://www.python.org/doc/2.3.5/lib/node304.html

.... the things that first-time users shouldn't be bothered with IMO are:

1. Getting a logger by name from a hierarchical namespace. There should be
a module-level log function that logs through the root logger.
2. Formatting the message (use a sensible default)
3. Adding a handler to a logger (artefact of the logging system).
4. Setting a log level (use a sensible default).

Perhaps there should be some module-level functions that make it easier to
'just log this message to that file'.

But I do think that adding logging to a cgi script is a sensible thing to
do for a beginner. Getting that to run in a debugger is probably way more
complicated.

--
René Pijlman
Feb 6 '06 #7

P: n/a
Rene Pijlman wrote:
But I do think that adding logging to a cgi script is a sensible thing to
do for a beginner. Getting that to run in a debugger is probably way more
complicated.


on the other hand, adding

if 1: # set to 0 when deploying
print "<pre>"
print cgi.escape(repr(os.environ))
print "</pre>"

to the CGI script isn't that hard... (if you're willing to do "view source" in
the browser, you can skip the <pre> and cgi.escape() stuff...)

</F>

Feb 6 '06 #8

P: n/a
Jim
> But I do think that adding logging to a cgi script is a sensible thing to
do for a beginner.

Let me second that. I happen to write a lot of CGI, and ISTM that
while you can do it without logging, you are condemming yourself to a
lot of staring at the screen, head-scratching, and saying ``Now what
could *that* mean?'' That is, CGI programming without logging seems to
me to ba a lot like general programming in Perl. :-}

Jim

Feb 7 '06 #9

P: n/a
Rene Pijlman wrote:
It struck me as somewhat complicated as well.

Looking at the basic example:
http://www.python.org/doc/2.3.5/lib/node304.html

... the things that first-time users shouldn't be bothered with IMO are:

1. Getting a logger by name from a hierarchical namespace. There should be
a module-level log function that logs through the root logger.
2. Formatting the message (use a sensible default)
3. Adding a handler to a logger (artefact of the logging system).
4. Setting a log level (use a sensible default).

Perhaps there should be some module-level functions that make it easier to
'just log this message to that file'.

But I do think that adding logging to a cgi script is a sensible thing to
do for a beginner. Getting that to run in a debugger is probably way more
complicated.


You should look at later versions of Python - your points above about
easier configuration have already been addressed: here's a link from
the current (2.4) docs:

http://docs.python.org/lib/minimal-example.html

Regards,

Vinay Sajip

Feb 7 '06 #10

P: n/a
Vinay Sajip:
Rene Pijlman:
It struck me as somewhat complicated as well.
You should look at later versions of Python - your points above about
easier configuration have already been addressed: here's a link from
the current (2.4) docs:

http://docs.python.org/lib/minimal-example.html


Yes, that looks good. Thanks for pointing that out. So... my advice to OP
(if still alive) is:

Add logging to your program:
http://docs.python.org/lib/minimal-example.html

And log the environment:
http://www.python.org/dev/doc/newsty...-procinfo.html

:-)

--
René Pijlman
Feb 8 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.