capture bash output values inside perl script

Viewed 87

I have a bash script that sets two variables to values (not a STDOUT) . I want to store those variables inside a perl script.

Sorry dont have example.. but this is the requirement. any thoughts please

In shell script i am doing something like this

source <Script Name> <Variable1> <Variable2>
Value1=$output1
Value2=$output2

===================== I want to do same inside perl

Tried

system("sh <Script> <Variable1> <Variable2>");
$Value1 = "$output1";
$Value2 = "$output2";
print $Value1 

Getting Blank

2 Answers

To build on the answer by @Snorik, here is one way you can do it:

system 'bash', '-c', 'source xyz.sh; echo -n $output1 >1.txt; echo -n $output2 >2.txt';
my $output1 = `cat 1.txt`;
my $output2 = `cat 2.txt`;

As Bash doesnt allow to use actual return values, the easiest way is the bash script to write each value to a file and then read each value from the file.

Have a look at this

Related