Help

R

Rob

I have a small CGI script that attempts to create a file on the fly.
The script runs successfully from the command prompt. Although when I
execute in a browser the file does not get created and therefore the
contents are not displayed on the page. I have try several different
approaches all have fialed to correct this issue. I have checked the
promissions, I am login in under the httpd userid, I have checked the
rc on the system command(see below), and have hit the wall.

HERE IS THE SCRIPT:
****************************************************************************
#!/usr/bin/perl -w
use strict;
use CGI ':standard';

my @fcetabs;
my @tablist;
my $dbin=param('database');

system("./list $dbin _ list.$$") || print "Bad Return Code from system
call: $?\n";
open(FCELST, "list.$$") || print "Database $dbin is currently
unavailable: $!";

while(<FCELST>){
@fcetabs=split;
push @tablist, $fcetabs[0];
}
close(FCELST);
system("rm ./list.$$");

print header;
print start_html('Table Selection');
showtabs(@tablist);
print end_html;

sub showtabs {
print start_form(-name=>'lstfield'),
h2('Please select a table for list of fields:'),
radio_group(-name=>'tables',-values=>[@_]),
p(),
submit(-name=>'lflds',-label=>'List Fields'),
end_form;
}

HERE IS THE OUTPUT FROM THE COMMAND LINE:
****************************************************************************
/cgi-bin> listfce.cgi database=sample
Bad Return Code from system call: 0
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Table Selection</TITLE>
</HEAD><BODY><FORM METHOD="POST"
ENCTYPE="application/x-www-form-urlencoded" NAME="lstfield">
<H2>Please select a table for list of fields:</H2><INPUT TYPE="radio"
NAME="tables" VALUE="cust_items" CHECKED>cust_items<INPUT TYPE="radio"
NAME="tables" VALUE="customers">customers<INPUT TYPE="radio"
NAME="tables" VALUE="households">households<INPUT TYPE="radio"
NAME="tables" VALUE="item_codes">item_codes<INPUT TYPE="radio"
NAME="tables" VALUE="items">items<INPUT TYPE="radio" NAME="tables"
VALUE="promo_codes">promo_codes<INPUT TYPE="radio" NAME="tables"
VALUE="promotions">promotions<INPUT TYPE="radio" NAME="tables"
VALUE="transactions">transactions<P><INPUT TYPE="submit" NAME="lflds"
VALUE="List Fields"><INPUT TYPE="hidden" NAME=".cgifields"
VALUE="tables"></FORM></BODY></HTML>

For some reason the or condition trips for the system command,
although the rc is zero. The HTML is correct, when pasted into a
..html and viewed it does display properly. Although via a browser
none of the information from the file is on the page???? I removed
the system (rm command and the file does not get created???
 
T

Tore Aursand

I have a small CGI script that attempts to create a file on the fly.

First of all: Your subject is not the subject of your posting. The
subject should be the _subject_ of the posting.
The script runs successfully from the command prompt.

Which means that there are no errors in the script, right?
Although when I execute in a browser [...]

No browsers - that I'm aware of - supports execution of Perl scripts. I
might be wrong, though.

What you actually mean, I guess, is that the web server executes, or tries
to execute, the script. Right?

Conclusion: There is obviously nothing wrong with your script as it runs
fine from the command line. When the (web) server is trying to execute
it, however, something fails. With this in mind, your question doesn't
seem to be related to Perl at all, right?

You should have posted your question in a newsgroup related to the (web)
server which executes your Perl scripts.

Am I totally wrong? If so, you should a described your problem better.
system("./list $dbin _ list.$$") || print "Bad Return Code from system
system("rm ./list.$$");

Are you sure these system calls are necessary? For the latter, you could
simple have used 'unlink';

"Deletes a list of files. Returns the number of files success-
fully deleted."

Anyway: I'm pretty tried right now, and I didn't try to run your code,
but I didn't see anywhere in the code that you try to create a file?
 
J

Jürgen Exner

Rob wrote:

[Subject: Help]

The Perl help is called "perldoc". You use it by simply calling the command
"perldoc" from the command line.
Try "perldoc perldoc" for an explanation of options.
I have a small CGI script that attempts to create a file on the fly.
The script runs successfully from the command prompt.

Then I guess your Perl program is correct.
Please see "perldoc -q 500" for further trouble shooting information for CGI
scripts.
Although when I execute in a browser

I may be wrong but IFAIK there is no browser that could execute a Perl
program.
the file does not get created [...]

[program snipped]

I may be wrong but there doesn't seem to be any command in that program that
would create a file.

jue
 
B

Ben Morrow

Tore Aursand said:
No browsers - that I'm aware of - supports execution of Perl scripts. I
might be wrong, though.

If you install PerlScript which comes with AS perl then IE will... ;)

Ben
 
J

Jürgen Exner

Ben said:
If you install PerlScript which comes with AS perl then IE will... ;)

Perlscript != Perl script
Or do you also believe that Javascript is the same as a Java script

jue
 
J

James Willmore

On 15 Nov 2003 06:09:56 -0800
(e-mail address removed) (Rob) wrote:

Pick a more descriptive subject line next time :)

use CGI ':standard';

use CGI qw:)standard -debug);

Using '-debug' will allow you to test at the command line. Now you'll
get:

jim@maxine:~> perl news4.pl
(offline mode: enter name=value pairs on standard input)
database=X
<CTRL-D> in *NIX or <CTRL-Z> in Windows

Notice that I did not pass the parameters _at_ the command line, but
was prompted for them. A lot easier to test :)

perldoc CGI

system("./list $dbin _ list.$$") || print "Bad Return Code from
system call: $?\n";

What is './list'? Can you execute just that at the command line?
And why '||' instead of 'or'? 'or' is more readable. And why not
'die' here? Later, you want to do something (it appears) with
'list.$$'. Is this a check to make sure you're not overwriting a file
that already exists?

If so, then why not

die "File exists\n" if(-e "list.$$");
open(FCELST, "list.$$") || print "Database $dbin is currently
unavailable: $!";

Again, why 'print' instead of 'die'?

system("rm ./list.$$");

More idiomatic Perl .....
unlink "list.$$" or die "Remove of file failed\n";

<snip>

This, should, get you started.

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Trying to be happy is like trying to build a machine for which
the only specification is that it should run noiselessly.
 
B

Ben Morrow

Jürgen Exner said:
Perlscript != Perl script
Or do you also believe that Javascript is the same as a Java script

Of course not. PerlScript is simply Perl, though, with all the MS COM
objects available as global variables as they are in Javascript.

Ben
 
J

Jay Tilton

(e-mail address removed) (Rob) wrote:

: I have a small CGI script that attempts to create a file on the fly.

Not really. You have a program that attempts to invoke a second program
which attempts to create a file. Big difference.

: The script runs successfully from the command prompt. Although when I
: execute in a browser the file does not get created and therefore the
: contents are not displayed on the page. I have try several different
: approaches all have fialed to correct this issue. I have checked the
: promissions, I am login in under the httpd userid, I have checked the
: rc on the system command(see below), and have hit the wall.
:
: HERE IS THE SCRIPT:
: ****************************************************************************
: #!/usr/bin/perl -w
: use strict;
: use CGI ':standard';
:
: my @fcetabs;
: my @tablist;
: my $dbin=param('database');
:
: system("./list $dbin _ list.$$") || print "Bad Return Code from system
: call: $?\n";

The error message will be emitted when system() returns 0 . External
programs typically return 0 to indicate no error has occurred.

Emphasize "typically." The ./list program is obliged to return non-zero
in case of a show-stopping error, but it's not a certainty. It could be
falling over dead and not telling anybody.

The Perl program looks fine. Since the ./list program generates all the
data used by the Perl program, troubleshooting efforts should be focused
on what ./list is really doing. We know nothing about that program, so
we cannot adequately help.

: open(FCELST, "list.$$") || print "Database $dbin is currently
: unavailable: $!";

Instead of creating an intermediate data file, you might want to see if
the data generated by ./list can be brought in through a piped open().
Not only would it make the post-run file cleanup unnecessary, but it
would prevent simultaneous CGI requests from wrecking each others' data.

[snip remainder]
 
L

LÄÊ»ie Techie

I have a small CGI script that attempts to create a file on the fly.
The script runs successfully from the command prompt. Although when I
execute in a browser the file does not get created and therefore the
contents are not displayed on the page. I have try several different
approaches all have fialed to correct this issue. I have checked the
promissions, I am login in under the httpd userid, I have checked the
rc on the system command(see below), and have hit the wall.

HERE IS THE SCRIPT:
****************************************************************************
#!/usr/bin/perl -w
use strict;
use CGI ':standard';

my @fcetabs;
my @tablist;
my $dbin=param('database');

system("./list $dbin _ list.$$")
|| print "Bad Return Code from system call: $?\n

Why do you reference "list" using a relative path? Are you sure the
current directory when your server executes the script?

If the execution of "list" fails, don't you want to croak or die instead
of merely printing to STDOUT? Does "list" print anything to STDOUT which
may mess up your HTTP headers?

[snip rest of code /]
HERE IS THE OUTPUT FROM THE COMMAND LINE:
****************************************************************************
/cgi-bin> listfce.cgi database=sample
Bad Return Code from system call: 0

A return value of "0" indicates success. Perhaps you should use "and"
instead of "||".

Aloha,
La'ie Techie
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top