Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- use IPC::System::Simple qw(system capture);
- # Run a command, wait until it finishes, and make sure it works.
- # Output from this program goes directly to STDOUT, and it can take input
- # from your STDIN if required.
- system($^X, "yourscript.pl", @ARGS);
- # Run a command, wait until it finishes, and make sure it works.
- # The output of this command is captured into $results.
- my $results = capture($^X, "yourscript.pl", @ARGS);
- # Both of these commands allow an exit value of 0, 1 or 2 to be considered
- # a successful execution of the command.
- system( [0,1,2], $^X, "yourscript.pl", @ARGS );
- # OR
- capture( [0,1,2, $^X, "yourscript.pl", @ARGS );
- #!/usr/bin/perl
- open PERLFILE, "<somePerlScript.pl";
- undef $/; # this allows me to slurp the file, ignoring newlines
- my $program = <PERLFILE>;
- eval $program;
- {
- local @ARGV = qw<param1 param2 param3>;
- do '/home/buddy/myscript.pl';
- }
- {
- local @ARGV = qw<param1 param2 param3>;
- do '/home/buddy/myscript.pl';
- }
- #!/usr/bin/perl
- use strict;
- open(OUTPUT, "date|") or die "Failed to create process: $!n";
- while (<OUTPUT>)
- {
- print;
- }
- close(OUTPUT);
- print "Process exited with value " . ($? >> 8) . "n";
- # On Unix systems, either of these will execute and just carry-on
- # You can't collect output that way
- `myscript.pl &`;
- system ('myscript.pl &');
- # On Windows systems the equivalent would be
- `start myscript.pl`;
- system ('start myscript.pl');
- # If you just want to execute another script and terminate the current one
- exec ('myscript.pl');
Add Comment
Please, Sign In to add comment