Here's
the function I use to send out external commands in my test harness. I like to
do all my external commands through this function so that I can control it at
one point. I log and timestamp all commands so I can make debugging problems
easier. I have some rough code in there that applies to specific things I do,
but you can yank that out easy enough.
# @<standard_output> =
xcmd(<command_string>,<outfile>);
# This function executes an external command. All external commands
# should go through this function. That way if we have to massage
# the external cmd for a given OS we can do it all in one place.
sub xcmd {
my($cmd) = $_[0];
my($outfile) = $_[1];
$cmd =~ s/\t/ /g;
$cmd =~ s/ +/ /g;
if( hay(lc($cmd),"program files") && hay(lc($cmd),"agchkpt") ) {
$cmd =~ s/Program Files/Program_Files/g;
$cmd =~ s/program files/Program_Files/g;
my(@w) = split(/ +/,$cmd);
$w[0] = "\"".$w[0]."\"";
#$w[1] = $w[1]."\"";
$cmd = join(" ",@w);
# This function executes an external command. All external commands
# should go through this function. That way if we have to massage
# the external cmd for a given OS we can do it all in one place.
sub xcmd {
my($cmd) = $_[0];
my($outfile) = $_[1];
$cmd =~ s/\t/ /g;
$cmd =~ s/ +/ /g;
if( hay(lc($cmd),"program files") && hay(lc($cmd),"agchkpt") ) {
$cmd =~ s/Program Files/Program_Files/g;
$cmd =~ s/program files/Program_Files/g;
my(@w) = split(/ +/,$cmd);
$w[0] = "\"".$w[0]."\"";
#$w[1] = $w[1]."\"";
$cmd = join(" ",@w);
$cmd =~ s/Program_Files/Program
Files/g;
#$cmd =~ s/Program Files/\"Program Files\"/g;
#$cmd =~ s/program files/\"Program Files\"/g;
$cmd =~ s/\//\\/g;
$cmd =~ s/\\+/\\/g;
$cmd =~ s/\-a false file://g;
$cmd =~ s/\-b false file://g;
$cmd =~ s/\-t false file://g;
$cmd =~ s/\-s false file://g;
}
#$cmd =~ s/Program Files/\"Program Files\"/g;
#$cmd =~ s/program files/\"Program Files\"/g;
$cmd =~ s/\//\\/g;
$cmd =~ s/\\+/\\/g;
$cmd =~ s/\-a false file://g;
$cmd =~ s/\-b false file://g;
$cmd =~ s/\-t false file://g;
$cmd =~ s/\-s false file://g;
}
if( hay(lc($cmd),"program
files") && !hay(lc($cmd),"agchkpt") )
{
#my(@w) = split(/ +/,$cmd);
#$w[0] = "\"".$w[0];
#$w[1] = $w[1]."\"";
#$cmd = join(" ",@w);
#my(@w) = split(/ +/,$cmd);
#$w[0] = "\"".$w[0];
#$w[1] = $w[1]."\"";
#$cmd = join(" ",@w);
$cmd =~ s/Program Files/\"Program
Files\"/g;
$cmd =~ s/program files/\"Program Files\"/g;
$cmd =~ s/\//\\/g;
$cmd =~ s/\\+/\\/g;
$cmd =~ s/\-a false file://g;
$cmd =~ s/\-b false file://g;
$cmd =~ s/\-t false file://g;
$cmd =~ s/\-s false file://g;
}
$cmd =~ s/program files/\"Program Files\"/g;
$cmd =~ s/\//\\/g;
$cmd =~ s/\\+/\\/g;
$cmd =~ s/\-a false file://g;
$cmd =~ s/\-b false file://g;
$cmd =~ s/\-t false file://g;
$cmd =~ s/\-s false file://g;
}
print
"XCMD:[$cmd]\n";
my($date) = time."::".getdate();
if( $outfile ne "" ) {
savearray(">>$outfile",$date,$cmd);
}
my(@out) = `$cmd`;
#if( hay(@out,"not recognized as") ) { showbanner("BANG:"); print "($cmd)\n"; }
return(@out);
}
my($date) = time."::".getdate();
if( $outfile ne "" ) {
savearray(">>$outfile",$date,$cmd);
}
my(@out) = `$cmd`;
#if( hay(@out,"not recognized as") ) { showbanner("BANG:"); print "($cmd)\n"; }
return(@out);
}
---
[EMAIL PROTECTED] (Galactic Hero)
Diplomacy: The art
of saying good doggie
while searching for a big rock.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Wayne Cain
Sent: Wednesday, May 23, 2001 9:42 AM
To: [EMAIL PROTECTED]
Subject: [Perl-unix-users] Perl script calls to command line?Hello
I have a perl script that is called from an application where I have access to application system variables and I prompt for other data. Now I need to execute another application command with the data I retrieved in the perl script. The perl script errors stating the command is not recognized and I agree with that error.
How can I have a perl script execute a command-line command in Unix and NT DOS?????
Any help would be greatly appreciated!
Wayne Cain