On 10/16/18 3:59 AM, ToddAndMargo via perl6-users wrote:

This is going through a rewrite.  So, don't help me until
I clean this up.  I hope to have some time Friday, but
maybe not.  I will get back.

-T

Rewrite worked!

sub RunNoShellAll( Str $RunString, Bool $StdOut, Bool $StdErr, Bool $Code, --> List ) {
   # --> List returns
   #    StdOut as Str $ReturnStr
   #    StdErr as Str $ReturnErr
   #    Return Code ($?) as Int $RtnCode

   # $RunString   Comnad line to run without a shell
   # $StdOur      read and return the STDOUT       True/False
   # $StdErr      read and return the STDERR       True/False
   # $Code        read and return the return code  True/False

# Note: If reading the STDERR, it is PRESUMED you also will be reading the STDIN. # If only reading the return code, it is presumed that you want the STDERR
   #          and STDIN to be silent.

   # place each value into a cell in an array.  Keep quoted
   # values together
   # print "Run String = <$RunString>\n";


   my Buf $BufStdErr;
   my Str $ReturnStr = "";
   my Str $ReturnErr = "";
   my Int $RtnCode = 0;
   my $proc;

   my @RunArray  = $RunString ~~ m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /;

   # shells remove the quote, so you have to here as well
   for @RunArray.kv -> $index, $value { @RunArray[$index] ~~ s:g/\"//; };
# for @RunArray.kv -> $index, $value { say "\$RunArray[$index] = <$value>"; }; print "\n";

if $StdErr { $proc = run( @RunArray, :err, :out, :enc<utf8-c8> ); } elsif $StdOut { $proc = run( @RunArray, :out, :enc<utf8-c8> ); } # STDERR goes to the terminal else { $proc = run( @RunArray, :err, :out, :enc<utf8-c8> ); } # STDIN and STDERR are silent

   if  $Code    { $RtnCode   = $proc.status; }
   if  $StdErr  { $ReturnErr = $proc.err.slurp; }
   if  $StdOut  { $ReturnStr = $proc.out.slurp; }

   return( $ReturnStr, $ReturnErr, $RtnCode );
}

Reply via email to