Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to call CGI, use pipes? (Please)

Status
Not open for further replies.

securityboy

Programmer
Dec 4, 2002
2
US
Hello -

I have a shell script that needs to run as me (not as "nobody"). I had it all set up in PHP but the web host only allows Perl programs to be cgiwrapped... so now I guess I'm trying to figure out how to use Perl to call the shell script:
(1) passing a string to it, and
(2) getting the resulting string back

Presumably this would be a simple task, but [I'm embarrassed to say that] I've been trying for many days.

Does anyone know where I can learn the syntax for this? Or maybe it's a simple two-liner that you can just give me, thereby soothing my numb brain. :)

Thanks very much. I really appreciate YOU taking a moment to help a brother out.

:b
 
there are several ways to execute and second piece of code
from within a piece of Perl. The simplest way which I think
would be sufficient for what you are doing is backticks.

Code:
#!/usr/local/bin/perl
use strict;
use CGI;
my $cgi_object = new CGI;

# use backticks to run the system 'ls' command
@files = `ls`;

print $cgi_object->header,
      $cgi_object->start_html,
      qq(<pre>@files</pre>),
      $cgi_object->end_html;

BUT! - be aware that running a system command via a CGI
program creates some huge security issues. Please see
the following link for details.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top