On Mar 23, 2004, at 9:12 AM, [EMAIL PROTECTED] wrote:

Hello,

I have some code that is using backticks, executing commands on the korn
shell.(if that matters). Most work as expected and i get the output of the
shell command assigned to the variable left of the argument, like with this
ls command and 'db2 connect' command.
<snips>
$is_dump = `ls $root_path$env/LOGS/ | grep dump`;

I'm sure someone else will answer your questions suitably, so I'll take my chance to preach. ;)


Backticks should generally be avoided. The above works I'm sure, but you can't count on ls and grep to be available and function identically everywhere. What you can count on is Perl, this wonderful language you are already using. The above, Perlified, looks more like this:

opendir DIR, "$root_path$env/LOGS/" or die "Directory error:  $!";
my @files = grep m/dump/, readdir DIR;
close DIR;

      $db_con = `db2 connect to $env user $dbuser using $dbpass`;
                if ($db_con =~ /$env/) {

Similarly, this looks like a job for the DBI.


James

<snips />

further down in my code i'm executing a shut down command and a start up
command using the same method. and in each of these instances, i'm
assigning the output of this command to the variable and adding it to the
body of an email.
<snips>
$stop_cmd = `./psadmin -p stop -d $env`;
$body .= $stop_cmd;
sleep 60;
$start_cmd = `./psadmin -p start -d $env`;
<snips />
the calls to the psadmin script prints to the shell and don't get assigned
to the variable. but they work exactly as expected. Is there a better way
to capture this output? i've tried some searching, but have not found
which FM to R :).


Thanks
Jeff










-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to