Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: System commands using CGI

by ColonelPanic (Friar)
on Dec 03, 2012 at 09:07 UTC ( #1006824=note: print w/ replies, xml ) Need Help??


in reply to System commands using CGI

Obligatory standard response:

use strict; use warnings;

This will encourage you to write better code, in particular declaring all of your variables as lexical.

use CGI;

It is much better to use the CGI module to handle your output, rather than rolling your own. For a discussion of this, see one of the great ancient works of the monastery.

use CGI::Carp qw/fatalsToBrowser/;

This enables you to see your script's fatal errors in the browser. Essential for debugging.

Finally, checking the error given by system would probably be helpful:

my $err = system("who",">>/var/www/cgi-bin/new.txt"); unless ($err == 0) { die "who command failed: $?"; }

See the documentation for system for more information on checking the error codes.



When's the last time you used duct tape on a duct? --Larry Wall


Comment on Re: System commands using CGI
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006824]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (15)
As of 2015-07-31 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (282 votes), past polls