I have a parent/calling shell script "parent.sh", this script is calling a perl script "child.pl". In "child.pl", I have "$x = 1000", how can I return x to the parent/calling "parent.sh" without using exit status?
Backticks allow you to capture the output of a child.
my $stdout_of_child = `perl -e'print 1000'`;
die( "Can't launch child: $!\n" ) if $? == -1;
die( "Child killed by signal ".( $? & 0x7F )."\n" ) if $? & 0x7F;
die( "Child exited with error ".( $? >> 8 )."\n" ) if $? >> 8;
See qx
in perlop for documentation.
See also capturex
from IPC::System::Simple, and IPC::Run.
To exchange more complicated data structures, you could serialize the data using JSON, YAML, etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.