From the variation on a theme department
spawn("./ntlogin.sh",undef,"data.out"); exit(0); # # spawn($cmd[,$env_vars,[,$stdout_log[,$stderr_log]]]) # $cmd = the command to execute # $env_vars = anonymous hash containing special environmenal # values (eg VAR => VALUE) # $stdout_log = a path to a log file for stdout # $stderr_log = a path to a log file for stderr sub spawn { my ($cmd_to_exec,$env_vars,$stdout_log,$stderr_log)=@_; my $pid=fork(); #Fork off! if ($pid > 0 ) { # This is the parent process return $pid; } elsif ( $pid == 0 ) { # this is the child if ($env_vars) { # # We have special environmental vars to pass foreach my $key(keys %$env_vars) { $ENV{$key}=$env_vars->{$key}; } } # # Next we want to close STDOUT and STDERR close STDOUT; close STDERR; # # Check to see if we have a filename passed if ($stdout_log) { # # If there is no stderr_log if (! $stderr_log) { $stderr_log=">&STDOUT"; } else { $stderr_log="> " . $stderr_log; } $stdout_log="> $stdout_log"; open STDOUT,$stdout_log or die "$stdout_log:$!"; open STDERR,$stderr_log or die "$stderr_log:$!"; } # # Finally we exec the command exec $cmd_to_exec or die "$cmd_to_exec: $!"; } else { die "Could not fork! :$!"; } }
That's code hot off pressses. That's a sniglet from some code I wrote for an startup script to replace some crippleware one of our vendors supplied with their product.
| Peter L. Berghold | Brewer of Belgian Ales |
| Peter@Berghold.Net | www.berghold.net |
| Unix Professional | |
In reply to Re: execution of cmmand inside a program
by blue_cowdawg
in thread execution of cmmand inside a program
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |