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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a Unix Shell Script with parameters

Status
Not open for further replies.

PerlPro

Programmer
Nov 14, 2003
7
US
Hi,

I am new to the Perl environment. I am trying to call a Unix shell script from a Perl CGI script. I need to pass 13 parameters to the Unix Shell Script.

Things I Do Know:
1) How to use 'shell()' function in Perl

My question:
1) How do I pass parameters from a Perl script inside the shell function?

eg) my $cmd = system('ex3.cgi $userLogin $userPwd');

Like I said, ex3.cgi is a unix shell script. $userLogin & $userPwd are scalar variables in perl with some string value. These parameters should be passed onto $1 and $2 in the unix shell script (ex3.cgi).

P.S: The above command works fine if I use literal strings instead of the variables.

Kindly help me if someone knows the solution.

Thank You.

 
Hi PerlPro,

The problem comes from the fact that you're using single quotes for your system string rather than double quotes.

Try it like this:

my $cmd = system("ex3.cgi $userLogin $userPwd");


Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Hi Mark,

Thanks for your prompt reply. I tried to use double quotes but it does not work. Here is some of my code. The parameters are passed from a URL.

#!/usr/bin/perl -w
use CGI ':standard';
my $userLogin;
my $usrPassword;

$userLogin = param('userlogin');
$usrPassword = param('password');

my $cmd = system("ex3.cgi $userLogin $usrPassword");

print "Content-type: text/html";
print "My UserID is $userLogin";
print "My cmdVal is $cmd";

It returns an error of 256.

Thanks again!

 
Hi again,

Well -- your Perl code is ok now.

What value does ex3.cgi return from the command line?

Have you tried specifying the complete path to ex3.cgi when you run it from inside your script?

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Hi Mike,

The value of cmd returned is 256.

This script is being called from a HTML page from where the parameters are passed. Now, if I call my routine from the unix shell prompt, it works fine. However, when I pass the parameters from a HTML page, the code returns the above error in variable cmd.

Thank You.

 
If calling your cgi really works from the unix shell, the cgi is retrieving values from the argv array, not the web server. Normally cgi scripts read 'GET' vars from the WEB server as STDIN is redefined to come from the WEB server.

Try this:
my $cmd = `ex3.cgi $userLogin $usrPassword`;
 
And have you tried specifying the complete path?

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top