develooper Front page | perl.perl6.users | Postings from November 2019

Re: qx and echo question

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
November 29, 2019 03:14
Subject:
Re: qx and echo question
Message ID:
53563b4b-b1aa-1356-f3fe-d56722cacd50@zoho.com
On 2019-11-28 12:57, yary wrote:
> One of the clues is the exitcode=1, there is an error coming back.
> 
> I think there are two issues which I didn't realize until now
> 1. DOS command "dir" is a cmd.exe built-in, not its own executable
> 2. Raku (perl6) "run" takes a list of arguments, not a space-separated 
> command-line
> 
> Let's try these (I still don't have my windows machine with me)
> 
> perl6 -e "my $proc=run qw[cmd /c dir]; say 'Exit code=', $proc.exitcode;"

C:\NtUtil>perl6 -e "my $proc=run qw[cmd /c dir]; say 'Exit code=', 
$proc.exitcod
e;"
  Volume in drive C is DRIVE_C
  Volume Serial Number is 3CDF-1B03

  Directory of C:\NtUtil

11/27/2019  20:57    <DIR>          .
11/27/2019  20:57    <DIR>          ..
11/27/2019  19:59    <DIR>          .precomp
07/09/2019  19:02               136 AppendToLogTest.bat
07/09/2019  18:23               805 KillSomeRunningTasks.bat
07/09/2019  18:17                51 ls.bat
05/01/2016  20:02                85 MathTest.bat
05/01/2016  19:59               393 out.txt
07/09/2019  18:12               840 TaskKillAndReboot.bat
05/01/2016  19:59               333 VarTest.bat
                7 File(s)          2,643 bytes
                3 Dir(s)  13,500,203,008 bytes free
Exit code=0


> 
> qw[cmd /c dir] is the same as 'cmd', '/c', 'dir'
> 
> perl6 -e "my $proc=run qw[cmd /c dir c:/NtUtil]; say 'Exit code=', 
> $proc.exitcode;"
> 

C:\NtUtil>perl6 -e "my $proc=run qw[cmd /c dir c:/NtUtil]; say 'Exit 
code=', $pr
oc.exitcode;"
Parameter format not correct - "NtUtil".
Exit code=1


> perl6 -e "chdir 'c:/NtUtil'; my $proc=run qw[cmd /c dir]; say 
> 'Exit code=', $proc.exitcode;"

C:\NtUtil>perl6 -e "chdir 'c:/NtUtil'; my $proc=run qw[cmd /c dir]; say 
'Exit c
de=', $proc.exitcode;"
  Volume in drive C is DRIVE_C
  Volume Serial Number is 3CDF-1B03

  Directory of c:\NtUtil

11/27/2019  20:57    <DIR>          .
11/27/2019  20:57    <DIR>          ..
11/27/2019  19:59    <DIR>          .precomp
07/09/2019  19:02               136 AppendToLogTest.bat
07/09/2019  18:23               805 KillSomeRunningTasks.bat
07/09/2019  18:17                51 ls.bat
05/01/2016  20:02                85 MathTest.bat
05/01/2016  19:59               393 out.txt
07/09/2019  18:12               840 TaskKillAndReboot.bat
05/01/2016  19:59               333 VarTest.bat
                7 File(s)          2,643 bytes
                3 Dir(s)  13,500,186,624 bytes free
Exit code=0


> 
> If you want to interpolate variables and still have a space-separated 
> list, use qqw instead of qw. Unix-y example:
> 
> perl6 -e 'my $dir="/tmp", my $proc=run qqw[ls $dir]; say $proc.exitcode'

C:\NtUtil>perl6 -e 'my $dir="/tmp", my $proc=run qqw[ls $dir]; say 
$proc.exitcod
e'
===SORRY!=== Error while compiling -e
Unable to parse expression in single quotes; couldn't find final "'" 
(correspond
ing starter was at line 1)
at -e:1
------> 'my<HERE><EOL>
     expecting any of:
         single quotes
         statement list
         term

> 
> ... and now I remember Raku has a "shell" routine that's like "run" but 
> it also creates a shell.
> 
> perl6 -e "my $proc=shell 'dir'; say 'Exit code=', $proc.exitcode;"

C:\NtUtil>perl6 -e "my $proc=shell 'dir'; say 'Exit code=', $proc.exitcode;"
  Volume in drive C is DRIVE_C
  Volume Serial Number is 3CDF-1B03

  Directory of C:\NtUtil

11/27/2019  20:57    <DIR>          .
11/27/2019  20:57    <DIR>          ..
11/27/2019  19:59    <DIR>          .precomp
07/09/2019  19:02               136 AppendToLogTest.bat
07/09/2019  18:23               805 KillSomeRunningTasks.bat
07/09/2019  18:17                51 ls.bat
05/01/2016  20:02                85 MathTest.bat
05/01/2016  19:59               393 out.txt
07/09/2019  18:12               840 TaskKillAndReboot.bat
05/01/2016  19:59               333 VarTest.bat
                7 File(s)          2,643 bytes
                3 Dir(s)  13,500,186,624 bytes free
Exit code=0

> perl6 -e "chdir 'c:/NtUtil'; my $proc=shell 'dir'; say 'Exit code=', 
> $proc.exitcode;"

C:\NtUtil>perl6 -e "chdir 'c:/NtUtil'; my $proc=shell 'dir'; say 'Exit 
code=', $
proc.exitcode;"
  Volume in drive C is DRIVE_C
  Volume Serial Number is 3CDF-1B03

  Directory of c:\NtUtil

11/27/2019  20:57    <DIR>          .
11/27/2019  20:57    <DIR>          ..
11/27/2019  19:59    <DIR>          .precomp
07/09/2019  19:02               136 AppendToLogTest.bat
07/09/2019  18:23               805 KillSomeRunningTasks.bat
07/09/2019  18:17                51 ls.bat
05/01/2016  20:02                85 MathTest.bat
05/01/2016  19:59               393 out.txt
07/09/2019  18:12               840 TaskKillAndReboot.bat
05/01/2016  19:59               333 VarTest.bat
                7 File(s)          2,643 bytes
                3 Dir(s)  13,500,186,624 bytes free
Exit code=0

> perl6 -e "my $proc=shell 'dir c:/NtUtil' ; say 'Exit code=', 
> $proc.exitcode;"

C:\NtUtil>perl6 -e "my $proc=shell 'dir c:/NtUtil' ; say 'Exit code=', 
$proc.exi
tcode;"
Parameter format not correct - "NtUtil".
Exit code=1


> 
> -y

Hi Yary,

Wow!   Thank you!!!!!

-T


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About