shell - How to execute python code from perl program and use output of python code -
i want execute python script perl code. want save python output array , data it. python script search in disk , locate files need. use output , play in next script.
i wrote code
use strict; use warnings; use getopt::long; $opt_section; $opt_content; $opt_ver; $opt_help = 0; &getoptions ( "help" => \$opt_help, "section:s" => \$opt_section, "content:s" => \$opt_content, "ver:s" => \$opt_ver, ); if ($opt_help) { print "usage: file.pl -section <section> -content <content> -ver <ver> \n "; exit;} ###################python script stats here ################ $py = `/home/priya/library/bin/find.py -filter test~${opt_section}_priya_${opt_ver}` ; print "output $py \n";
code executing python script , displaying output on terminal screen. not storing output $py. can please hep me direct output array or scalar? later want use every line of python output.
it appears if find.py outputting stderr. try following redirects stderr (filehandle 2) stdout (filehandle 1) 2>&1
, fills array @python_output
resulting lines.
my @python_output = qx(/home/priya/library/bin/find.py -filter test~${opt_section}_priya_${opt_ver} 2>&1);
see http://perldoc.perl.org/perlop.html#qx%2f_string_%2f several examples of how wrangle stderr , stdout in pipes.
Comments
Post a Comment