Greetings all,
I am trying to assign the results of a background process to $variable.
I can't seem to get the correct syntax, could one of you good people
assist?
Below is a snippet of what I have ( running on Solaris 2.6 ), I know
there are more elegant ways to do this. I'm open to any suggestions.
I want the results of the ( echo $! ) to be assigned to
( $save_this_pid ) and returned, so I can do other processing like
create a pid file.
$pid = &run_sh_commands("[ -f $logfile ] && mv $logfile $logfile.$time >
/dev 2>&1",
"echo \"## $0: restarted on `date`\"
>> $logfile",
"$appdir{$os}/$app_name{$port}->{name}
$app_options >> $logfile 2>&1 &",
"echo \$!")
unless ($DEBUG_MODE);
......
sub run_these_sh_commands {
my @commands = @_;
open(PIPE, "|sh") || die;
foreach $command (@commands)
{
if ( $command =~ /(echo\s\$!)$/
{
$save_this_pid = ( something would go here but I don't know
what )
# otherwise, the pid number gets printed to the screen and
I want to save it.
{
else
{
print PIPE "$command\n";
}
return($save_this_pid);
}
close(PIPE);
}
Thanks,
gS