user3309525
user3309525

Reputation: 71

Call perl script from another perl script with parameters

I'm trying to call perl1.pl which is in another folder with switches from another perl script say perl2.pl. Usually perl1 is called like:

perl1.pl -arg $arg1 -arg2 $arg2

Now the problem is $arg1 gets generated internally from program perl2 and $arg2 is obtained from the switch when perl2 is executed like this.

perl2 -arg2 $arg2.

I tried using system command to call perl1.pl but it isn't working. Is there any way to do this? There are also few arguments in perl1 which accepts from the user which are always required. I'm not sure how to send them.

Upvotes: 1

Views: 2456

Answers (2)

serenesat
serenesat

Reputation: 4709

You can use CPAN module IPC::System::Simpleto capture the output. For more details have a look here : IPC::System::Simple

my $output = capture("some_command", @args);

Upvotes: 0

user1126070
user1126070

Reputation: 5069

Some example would be usefull. You could use backticks to capture the output of an executable.

### in perl1
my $ret = `$perl2 -arg2 $arg2`;
chomp($ret);
print "ret: $ret\n";

Upvotes: 1

Related Questions