473,378 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Strange behavior with os call in cgi script

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
10 1179
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
OK, interesting, but just how dow I print he environment in the
program??

Feb 5 '06 #3
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: paul reed | last post by:
Hello, I am having some weird behavior between two machines...one which is running the 1.1 framework and one which is running 1.0. After opening a child form from a parent...I update the...
0
by: Ronen | last post by:
I have a strange behavior with dialog windows postbacks Here is what I doing: 1. Call window.showModalDialog('webForm1.aspx') from script. (I also using <base target="_self">) 2. After the dialog...
2
by: Jim Bancroft | last post by:
Hi everyone, I have a DropDownList I populate as outlined below. This is from my code-behind file: private void Page_Load(object sender, System.EventArgs e) { BindMyData(); DataBind(); }
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
7
by: Tim_Mac | last post by:
hi, using .net 2.0, i have a web form with lots of textboxes, drop-down-lists etc. There are lots of required field validators and regular expression validators. When i click the 'save' button,...
10
by: John Kraft | last post by:
Hello all, I'm experiencing some, imo, strange behavior with the StreamReader object I am using in the code below. Summary is that I am downloading a file from a website and saving it to disk...
3
by: Chuck Renner | last post by:
Please help! This MIGHT even be a bug in PHP! I'll provide version numbers and site specific information (browser, OS, and kernel versions) if others cannot reproduce this problem. I'm...
10
by: silverbob | last post by:
I am replacing my Javascript-called files with SSI, and I'm getting an unexpected result with my page footer. I can really use some help with this. The footer contains a copyright (left...
4
by: r | last post by:
Hello, It seems delimiters can cause trouble sometimes. Look at this : <script type="text/javascript"> function isDigit(s) { var DECIMAL = '\\.'; var exp = '/(^?0(' + DECIMAL
20
by: Pilcrow | last post by:
This behavior seems very strange to me, but I imagine that someone will be able to 'explain' it in terms of the famous C standard. -------------------- code -----------------------------------...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.