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. BergholdBrewer of Belgian Ales
Peter@Berghold.Netwww.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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.