http://www.perlmonks.org?node_id=1083231


in reply to Running blocks of shell script from within perl script

Yes, indeed.   exec, by any other name, can only “execute” one ... “something.”   Therefore, if you want that “one something” to consist of “executing many commands,” you need to persuade “the host, whoever it is ...” to execute “many commands” as “one something.”   :-D   In other words, you need to build some kind of a shell-script.   Construct such a script (if necessary).   Then, make it “executable.”   Then, execute “it,” and gather-up its [combined ...] output.   Q.E.D.

“Perl or not ...” and, pretty much, regardless of operating system, this will be the way that you can get this kind of requirement done.

Replies are listed 'Best First'.
Re^2: Running blocks of shell script from within perl script
by lilgreen (Sexton) on Apr 22, 2014 at 21:32 UTC

    Using this mentality I've got this to work:

    sub exec_check { my (%check) = @_; my $script = './fh.tmp'; open( my $out, '>', $script ); print $out $check{'CHECK_CODE'}; close($out); system("chmod 755 $script"); my @return = qx/$script/; foreach (@return) { my ($status, $string) = split(";", $_); print_output($status, $string); } system("rm $script"); }

    It still seems a bit inelegant, but maybe with as with so many perl things it's just as elegant as it's going to get :\

Re^2: Running blocks of shell script from within perl script
by marto (Cardinal) on Apr 22, 2014 at 21:30 UTC

    “Perl or not ...”

    There you go again, quoting something that nobody said.

      Please ... just skip it.   Skip the personal jabs and stick to the subject of the thread.   My comment is very clearly meant to say that “in this case it does not matter whether you are using the Perl programming language ... or any programming language ... or not.”   I cannot help but conclude that my intentions were quite clear.

      Hmm.   Site logged me out.   Nearby comment obviously was mine.

        take you own advice, stick to the subject of the thread. Your PEBKAC issue is well known.