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

Re: qx and echo question

Thread Previous | Thread Next
From:
yary
Date:
November 28, 2019 20:57
Subject:
Re: qx and echo question
Message ID:
CAG2CFAb0RFObSLmGbHYW8DDR91M9VbKndm8vsMLOX6kMj2WdpQ@mail.gmail.com
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;"

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;"

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

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'

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

-y


On Wed, Nov 27, 2019 at 11:19 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

>
> >
> > On Mon, Nov 25, 2019 at 9:02 PM ToddAndMargo via perl6-users
> > <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> >
> >      >> On Mon, Nov 25, 2019 at 6:46 AM ToddAndMargo via perl6-users
> >      >> <perl6-users@perl.org <mailto:perl6-users@perl.org>
> >     <mailto:perl6-users@perl.org <mailto:perl6-users@perl.org>>> wrote:
> >      >>
> >      >>     Hi All,
> >      >>
> >      >>     In Perl6 for Windows, how can I get "qx" (or other) to
> >      >>     send the output to the shell as its happens (not
> >      >>     afterwards)?
> >      >>
> >      >>       >ver
> >      >>     Microsoft Windows [Version 6.1.7601]
> >      >>
> >      >>       >perl6 -e "qx ( ver );"
> >      >>     <nothing>
> >      >>
> >      >>
> >      >>     (One of) my goal(s) is to watch "chkdsk" on the shell
> >      >>     as it runs through its various stages.
> >      >>
> >      >>     I might want the error code back.
> >      >>
> >      >>     Many thanks,
> >      >>     -T
> >
> >
> >
> >     On 2019-11-25 07:25, yary wrote:
> >      > So, you want to see the output as it happens, and the program
> >     doesn't
> >      > need the output, it only needs the error code?
> >      >
> >      > my $proc = run 'ls';
> >      > say $proc.exitcode ?? 'error' !! 'good' ;
> >      >
> >      > I got that from the examples on
> >     https://docs.perl6.org/type/Proc#sub_run
> >      > - even if documentation usually leaves you cold, that page has
> >     samples
> >      > which look simple and useful.
> >      >
> >      > -y
> >
> >     Hi Yary,
> >
> >     Thank you!
> >
> >     I can't figure out
> >
> >     1) where it is getting its path from
> >
> >     2) why it looks so weird
> >
> >     -T
> >
> >     C:\NtUtil>perl6 -e "my $proc=run( dir ); say $proc.exitcode;"
> >
> >     C:\NtUtil>echo.
> >     1>>C:\ProgramData\IperiusBackup\Logs\Job001\LogFile.txt
> >
> >     C:\NtUtil>echo 12345
> >     1>>C:\ProgramData\IperiusBackup\Logs\Job001\LogFile.txt
> >     0
> >
> >
> >     C:\NtUtil>perl6 -e "my $proc=run( dir 'c:\NtUtil' ); say
> >     $proc.exitcode;"
> >
> >     C:\NtUtil>echo.
> >     1>>C:\ProgramData\IperiusBackup\Logs\Job001\LogFile.txt
> >
> >     C:\NtUtil>echo 12345
> >     1>>C:\ProgramData\IperiusBackup\Logs\Job001\LogFile.txt
> >     0
> >
>
> On 2019-11-26 15:33, yary wrote:
>  > quote the argument to run - try the below - and yes, I switched to
>  > forward slash. My experience is that Windows accepts either slash, and
>  > forward slashes create fewer confusing situations.
>  >
>  > perl6 -e "my $proc=run 'dir'; say 'Exit code=', $proc.exitcode;"
>  > perl6 -e "chdir 'c:/NtUtil'; my $proc=run 'dir'; say 'Exit code=',
>  > $proc.exitcode;"
>  > perl6 -e "my $proc=run 'dir c:/NtUtil' ; say 'Exit code=',
> $proc.exitcode;"
>  >
>  > -y
>  >
>
> Hi Yary,
>
> I am not seeing the std out from the command.  I do not
> want to capture it with perl.  What am I missing?
>
>
>
> C:\NtUtil>perl6 -e "my $proc=run 'dir'; say 'Exit code=', $proc.exitcode;"
> Exit code=1
>
> C:\NtUtil>perl6 -e "my $proc=run 'dir c:/NtUtil' ; say 'Exit code=',
> $proc.exitc
> ode;"
> Exit code=1
>
> C:\NtUtil>perl6 -e "chdir 'c:/NtUtil'; my $proc=run 'dir'; say 'Exit
> code=', $pr
> oc.exitcode;"
> Exit code=1
>
> C:\NtUtil>perl6 -e "qx ( cmd.exe /C dir );"
> <nothing>
>
> Thank you for the help with this,
> -T
>

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