#!/usr/bin/env perl6

#`{
Run a system command without a shell

}

use lib "/usr/share/perl6/site/bin";
use strict;

sub RunNoShell ( $RunString) {
   #`{ run a system command without a shell.
       Enter the command as a sting.  Use quotes around items that are meant
       to be grouped together ("Prgoram Files", etc.)

       Results are returned as a dual pair:
           a string with the results of the command, and
           the return code (note: bash 0=success)
   }

   my @RunArray  = $RunString ~~ m:global/ [ '"' <-[ " ]> * '"' | \S+ ] /;
   for @RunArray.kv -> $index, $value { say "\$y[$index] = <$value>"; }; print "\n";

   my $proc      = run( @RunArray, :out );
   my $ReturnStr = $proc.out.get;
   my $RtnCode   = $proc.status;

   return ( $ReturnStr, $RtnCode );
}


my $x, my $y = RunNoShell( "ls -al /usr" );
say $x;
say $y;