RE: return code?
Todd, I cleaned up my code and published it (with the help of Patrick Spek -- thanks again). CPAN: https://modules.perl6.org/dist/Async::Command:cpan:MLDEVINE I’ve been using it in an enterprise environment with 1000+ UNIX/Linux servers. I’m able to launch hundreds of SSH commands at once and sort out each Proc::Async’s $*OUT and $*ERR without line noise. For version 0.0.2 I hardcoded a throttle of 16 threads after graphing performance on a 4 x Linux VM – seems safe yet efficient. Criticisms & suggestions always welcome by Perl6 mentors. Thanks, Mark From: Mark Devine Sent: Saturday, July 28, 2018 16:38 To: ToddAndMargo Cc: perl6-users Subject: RE: return code? Todd, I see that you’re frequently running commands in your code like me. I was looking for a reliable reusable approach for commands for a long time. I’m still learning & not quite ready to step up to contribute to the ecosystem yet (https://docs.perl6.org/language/modules.html). After reading Perl 6 Fundamentals (Moritz Lenz), I cobbled together a reusable Command.pm6 for myself based on his examples. Method ‘run’ for a single async command, or methods ‘sow’+‘reap’ for multiple async (possibly all different) commands, with all returns collected in Command::Result objects. https://github.com/markldevine/perl6-Command Now whenever I need any general-purpose external command, I ‘use Command;’ and it has never failed me (I.e. curl, , ssh, etc.). Because it’s not in the ecosystem, git clone it into a directory and set PERL6LIB= or ‘use lib ’ internally. Docs are internal POD. If any of the Perl 6 big brains are reading this and would provide some welcome criticism resulting in something that should be published, I would upload as per the instructions it or hand it off to someone more capable of maintaining it. If you give it a try, I think that you might find it helpful. Thanks, Mark From: Brandon Allbery mailto:allber...@gmail.com>> Sent: Saturday, July 28, 2018 16:22 To: ToddAndMargo mailto:toddandma...@zoho.com>> Cc: perl6-users mailto:perl6-users@perl.org>> Subject: Re: return code? Yes, that's what I was addressing: you can tell run() to do that, keeping stderr separate with :err(). qxx does that internally. On Sat, Jul 28, 2018 at 4:12 PM ToddAndMargo mailto:toddandma...@zoho.com>> wrote: On 07/28/2018 12:56 PM, Brandon Allbery wrote: > You can control where run() sends things. Hi Brandon, I adore the run command. In this particular instance (curl's progress meter, which is written to STDERR), I want STDERR to write to the shell, but want to collect STDIN and the return code. curl ; echo $? will send both to STDIN, which I can easily deal with. -T -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com<mailto:allber...@gmail.com> ballb...@sinenomine.net<mailto:ballb...@sinenomine.net> unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: return code?
On 07/29/2018 03:03 AM, Patrick Spek via perl6-users wrote: You can use the head[2] sub to write it as for @ReturnAry.head(*.elems - 3) -> $line Also, on the $ReturnStr += $Line If you're trying to concatenate a string, you should use the ~ instead of the +, so it'd become $ReturnStr ~= $Line @ReturnAry[ 0 .. @ReturnAry.elems - 3 ] -> $Line { $ReturnStr ~= $Line ~ "\n"; } [@ReturnAry.elems - 2] is "$?" Thank you!
Re: return code?
*From:* Brandon Allbery *Sent:* Saturday, July 28, 2018 16:22 *To:* ToddAndMargo *Cc:* perl6-users *Subject:* Re: return code? Yes, that's what I was addressing: you can tell run() to do that, keeping stderr separate with :err(). qxx does that internally. On Sat, Jul 28, 2018 at 4:12 PM ToddAndMargo <mailto:toddandma...@zoho.com>> wrote: On 07/28/2018 12:56 PM, Brandon Allbery wrote: > You can control where run() sends things. Hi Brandon, I adore the run command. In this particular instance (curl's progress meter, which is written to STDERR), I want STDERR to write to the shell, but want to collect STDIN and the return code. curl ; echo $? will send both to STDIN, which I can easily deal with. -T On 07/28/2018 01:38 PM, Mark Devine wrote: Todd, I see that you’re frequently running commands in your code like me. I was looking for a reliable reusable approach for commands for a long time. I’m still learning & not quite ready to step up to contribute to the ecosystem yet (https://docs.perl6.org/language/modules.html). After reading Perl 6 Fundamentals (Moritz Lenz), I cobbled together a reusable Command.pm6 for myself based on his examples. Method ‘run’ for a single async command, or methods ‘sow’+‘reap’ for multiple async (possibly all different) commands, with all returns collected in Command::Result objects. https://github.com/markldevine/perl6-Command Now whenever I need any general-purpose external command, I ‘use Command;’ and it has never failed me (I.e. curl, , ssh, etc.). Because it’s not in the ecosystem, git clone it into a directory and set PERL6LIB= or ‘use lib ’ internally. Docs are internal POD. If any of the Perl 6 big brains are reading this and would provide some welcome criticism resulting in something that should be published, I would upload as per the instructions it or hand it off to someone more capable of maintaining it. If you give it a try, I think that you might find it helpful. Thanks, Mark Hi Mark, I will give it a look! I wrote my own "RunNoShell" and "RunNoShellErr". The later returns the STDERR. And I address both as a string, "rather" "than" "as" "chunks", "which" "I" "find" "clunky". I will post it to vpaste if you want to take a look. -T
Re: return code?
sh command. If any issues arise while using Assixt, feel free to hit me up, preferably through a GitLab issue. If anything is unclear on getting your module into the ecosystem, do not hesitate to ask on the mailing list. I can look into your module at various steps to confirm whether you're going into the right direction as well. [1]: https://choosealicense.com/ [2]: https://gitlab.com/tyil/perl6-app-assixt [3]: https://docs.perl6.org/language/testing [4]: https://docs.travis-ci.com/user/getting-started/ [5]: https://github.com/perl6/ecosystem [6]: https://pause.perl.org/ [7]: https://pause.perl.org/pause/query?ACTION=request_id On Sat, 28 Jul 2018 20:38:04 + Mark Devine wrote: > Todd, > > I see that you’re frequently running commands in your code like me. > I was looking for a reliable reusable approach for commands for a > long time. I’m still learning & not quite ready to step up to > contribute to the ecosystem yet > (https://docs.perl6.org/language/modules.html). After reading Perl 6 > Fundamentals (Moritz Lenz), I cobbled together a reusable Command.pm6 > for myself based on his examples. Method ‘run’ for a single async > command, or methods ‘sow’+‘reap’ for multiple async (possibly all > different) commands, with all returns collected in Command::Result > objects. > > https://github.com/markldevine/perl6-Command > > Now whenever I need any general-purpose external command, I ‘use > Command;’ and it has never failed me (I.e. curl, , ssh, etc.). > > Because it’s not in the ecosystem, git clone it into a directory and > set PERL6LIB= or ‘use lib ’ internally. Docs are internal > POD. If any of the Perl 6 big brains are reading this and would > provide some welcome criticism resulting in something that should be > published, I would upload as per the instructions it or hand it off > to someone more capable of maintaining it. > > If you give it a try, I think that you might find it helpful. > > Thanks, > > Mark > > From: Brandon Allbery > Sent: Saturday, July 28, 2018 16:22 > To: ToddAndMargo > Cc: perl6-users > Subject: Re: return code? > > Yes, that's what I was addressing: you can tell run() to do that, > keeping stderr separate with :err(). qxx does that internally. > > On Sat, Jul 28, 2018 at 4:12 PM ToddAndMargo > mailto:toddandma...@zoho.com>> wrote: On > 07/28/2018 12:56 PM, Brandon Allbery wrote: > > You can control where run() sends things. > > Hi Brandon, > > I adore the run command. > > In this particular instance (curl's progress meter, which is > written to STDERR), I want STDERR to write to the shell, but > want to collect STDIN and the return code. > > curl ; echo $? > > will send both to STDIN, which I can easily deal with. > > -T > > > -- > brandon s allbery kf8nh sine nomine > associates > allber...@gmail.com<mailto:allber...@gmail.com> > ballb...@sinenomine.net<mailto:ballb...@sinenomine.net> unix, > openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net -BEGIN PGP SIGNATURE- iQEzBAEBCAAdFiEE4eL662U9iK2ST2MqN/W6H45XOE8FAltdmfMACgkQN/W6H45X OE9FVAf+KkM7N7Qc7a96Llj61PS5an6klw3kSFWhlAYHlimhDKtaAXQ72anQj+Q+ L3Q43x/JLlBDkXm469KKkU9kKutqx5i8I6FikpZi3QVcaD4E3k7Vv7a41ZF7HrMe RUmcV8+woO58GgG49sSQ23FILfxa5oSanJxce8VdfhN7LX4HcdxYqOTXlmmg2Idt Ytl6JC+0TTKVMQ51oeZbCZpGQOvG5nor+YNn1ZEN739q9njia8SrEhDlj9Q2vdbN +QrGDdDUD3Z/EBMKCQoT84O+4q/Uk6YH9W0hO1A9ubakodxyJ1thlf/yFaPS2doX hDUj+MD5kOZKAwFuzAgDszkM0OqLTg== =lFKd -END PGP SIGNATURE-
Re: return code?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 I get the idea that you're trying to get a list of lines with the @ReturnAry = split "\n", qqx ( curl $TimeOutStr -L $Url -o $FileName; echo \$\? ); You can use the lines[1] sub for exactly this. Similarly for this line for @ReturnAry[ 0 .. @ReturnAry.elems - 3 ] -> $Line You can use the head[2] sub to write it as for @ReturnAry.head(*.elems - 3) -> $line Also, on the $ReturnStr += $Line If you're trying to concatenate a string, you should use the ~ instead of the +, so it'd become $ReturnStr ~= $Line [1]: https://docs.perl6.org/routine/lines [2]: https://docs.perl6.org/routine/head On Sat, 28 Jul 2018 23:46:30 -0700 ToddAndMargo wrote: > On 07/28/2018 01:37 AM, ToddAndMargo wrote: > > Hi All, > > > > How do I get the bash return code ("$?") from > > the following? > > > > $ReturnStr = qqx ( curl $TimeOutStr -L $Url -o $FileName ).lines; > > > > > > Many thanks, > > -T > > > Followup: > > This is what I came up with: > > if $ProgressBar { ># This need a space ofter the qqx ># $ p6 'my $x="cat /etc/hosts; echo \$\?"; my @y = split "\n", > qqx ( $x ); say @y[@y.elems-2];' ># 0 ># > > >@ReturnAry = split "\n", qqx ( curl $TimeOutStr -L $Url -o > $FileName; echo \$\? ); >for @ReturnAry[ 0 .. @ReturnAry.elems - 3 ] -> $Line { > $ReturnStr += $Line; } >print "\n"; >$ReturnCode = @ReturnAry[ @ReturnAry.elems - 2 ]; > > } else { >( $ReturnStr, $ReturnCode ) = RunNoShell ( "curl $TimeOutStr > -L $Url -o $FileName" ); > } > return ( $ReturnStr, $ReturnCode ); -BEGIN PGP SIGNATURE- iQEzBAEBCAAdFiEE4eL662U9iK2ST2MqN/W6H45XOE8FAltdkOYACgkQN/W6H45X OE+73gf+Ko8Wrm3aySxtsMsuVAWT+V4iNanSpEo8jj27+OUgQCmC1vY0yR7BkrJS vb1WnM2TvzrxBlc/L9QF7dJaJfBkcB2Nera+PJWkdZlYegvmA9vKHbjyxl/Nvyi6 8M1GjtsmTKUFz3OT3T60fXYiRwiu2vG+OBeN4riWDI4HO9OiXw+kqcuUsymavNo3 6YdXXhwyfKLx+kdsIT1UAfSfWY+B53attz/XwTkiz8VH3cSP1zQtvx+zh5KbvA+i CViRZQAvkeasQ77d70H9fd+oYhgJqHCF5/SSlB1MDP2Rn9YZDxhfDgsHuNEWjplm 7NTZDIMBn5JXLgSOkyulC+xIBG0sXg== =Dk+C -END PGP SIGNATURE-
Re: return code?
On 07/28/2018 11:46 PM, ToddAndMargo wrote: On 07/28/2018 01:37 AM, ToddAndMargo wrote: Hi All, How do I get the bash return code ("$?") from the following? $ReturnStr = qqx ( curl $TimeOutStr -L $Url -o $FileName ).lines; Many thanks, -T Followup: This is what I came up with: if $ProgressBar { # This need a space ofter the qqx # $ p6 'my $x="cat /etc/hosts; echo \$\?"; my @y = split "\n", qqx ( $x ); say @y[@y.elems-2];' # 0 # @ReturnAry = split "\n", qqx ( curl $TimeOutStr -L $Url -o $FileName; echo \$\? ); for @ReturnAry[ 0 .. @ReturnAry.elems - 3 ] -> $Line { $ReturnStr += $Line; } print "\n"; $ReturnCode = @ReturnAry[ @ReturnAry.elems - 2 ]; } else { ( $ReturnStr, $ReturnCode ) = RunNoShell ( "curl $TimeOutStr -L $Url -o $FileName" ); } return ( $ReturnStr, $ReturnCode ); This is what it looks like when run: $ GetUpdates.pl6 GetClassicShell Mozilla Mirror Checking GetClassicShell IsCurrentRevNewer::GetClassicShell: debugging statement: LatestRev <4.3.1> OldRev <0> GetUpdates.pl6::GetClassicShell: No new revision located % Total% Received % Xferd Average Speed TimeTime Time Current Dload Upload Total SpentLeft Speed 0 00 00 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 7019k 100 7019k0 0 783k 0 0:00:08 0:00:08 --:--:-- 825k GetClassicShell Debug: OldRev = 0 OldFileName = LatestRev = 4.3.1 NewFileName = /home/CDs/Windows/W10/ClassicShell/ClassicShellSetup-4.3.1.exe NewFileSize = 7187816 Status = 2 (Update) GetClassicShellnew update downloaded 0 --> 4.3.1
Re: return code?
On 07/28/2018 01:37 AM, ToddAndMargo wrote: Hi All, How do I get the bash return code ("$?") from the following? $ReturnStr = qqx ( curl $TimeOutStr -L $Url -o $FileName ).lines; Many thanks, -T Followup: This is what I came up with: if $ProgressBar { # This need a space ofter the qqx # $ p6 'my $x="cat /etc/hosts; echo \$\?"; my @y = split "\n", qqx ( $x ); say @y[@y.elems-2];' # 0 # @ReturnAry = split "\n", qqx ( curl $TimeOutStr -L $Url -o $FileName; echo \$\? ); for @ReturnAry[ 0 .. @ReturnAry.elems - 3 ] -> $Line { $ReturnStr += $Line; } print "\n"; $ReturnCode = @ReturnAry[ @ReturnAry.elems - 2 ]; } else { ( $ReturnStr, $ReturnCode ) = RunNoShell ( "curl $TimeOutStr -L $Url -o $FileName" ); } return ( $ReturnStr, $ReturnCode );
RE: return code?
Todd, I see that you’re frequently running commands in your code like me. I was looking for a reliable reusable approach for commands for a long time. I’m still learning & not quite ready to step up to contribute to the ecosystem yet (https://docs.perl6.org/language/modules.html). After reading Perl 6 Fundamentals (Moritz Lenz), I cobbled together a reusable Command.pm6 for myself based on his examples. Method ‘run’ for a single async command, or methods ‘sow’+‘reap’ for multiple async (possibly all different) commands, with all returns collected in Command::Result objects. https://github.com/markldevine/perl6-Command Now whenever I need any general-purpose external command, I ‘use Command;’ and it has never failed me (I.e. curl, , ssh, etc.). Because it’s not in the ecosystem, git clone it into a directory and set PERL6LIB= or ‘use lib ’ internally. Docs are internal POD. If any of the Perl 6 big brains are reading this and would provide some welcome criticism resulting in something that should be published, I would upload as per the instructions it or hand it off to someone more capable of maintaining it. If you give it a try, I think that you might find it helpful. Thanks, Mark From: Brandon Allbery Sent: Saturday, July 28, 2018 16:22 To: ToddAndMargo Cc: perl6-users Subject: Re: return code? Yes, that's what I was addressing: you can tell run() to do that, keeping stderr separate with :err(). qxx does that internally. On Sat, Jul 28, 2018 at 4:12 PM ToddAndMargo mailto:toddandma...@zoho.com>> wrote: On 07/28/2018 12:56 PM, Brandon Allbery wrote: > You can control where run() sends things. Hi Brandon, I adore the run command. In this particular instance (curl's progress meter, which is written to STDERR), I want STDERR to write to the shell, but want to collect STDIN and the return code. curl ; echo $? will send both to STDIN, which I can easily deal with. -T -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com<mailto:allber...@gmail.com> ballb...@sinenomine.net<mailto:ballb...@sinenomine.net> unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: return code?
Yes, that's what I was addressing: you can tell run() to do that, keeping stderr separate with :err(). qxx does that internally. On Sat, Jul 28, 2018 at 4:12 PM ToddAndMargo wrote: > On 07/28/2018 12:56 PM, Brandon Allbery wrote: > > You can control where run() sends things. > > Hi Brandon, > > I adore the run command. > > In this particular instance (curl's progress meter, which is > written to STDERR), I want STDERR to write to the shell, but > want to collect STDIN and the return code. > > curl ; echo $? > > will send both to STDIN, which I can easily deal with. > > -T > -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: return code?
On 07/28/2018 12:56 PM, Brandon Allbery wrote: You can control where run() sends things. Hi Brandon, I adore the run command. In this particular instance (curl's progress meter, which is written to STDERR), I want STDERR to write to the shell, but want to collect STDIN and the return code. curl ; echo $? will send both to STDIN, which I can easily deal with. -T
Re: return code?
You can control where run() sends things. See the :out and :err named parameters. I think :err($*ERR) is what you want here, although you might also want :err($*OUT) which effectively redirects its stderr to rakudo's stdout. (That said, I don't know if it processes those in the right order; it could be like the difference between >foo 2>&1 and 2>&1 >foo in shell. There have been a number of odd confusions in the history of that code.) On Sat, Jul 28, 2018 at 3:52 PM ToddAndMargo wrote: > >> On Sat, Jul 28, 2018 at 4:37 AM, ToddAndMargo >> <mailto:toddandma...@zoho.com>> wrote: > >> > >> Hi All, > >> > >> How do I get the bash return code ("$?") from > >> the following? > >> > >> $ReturnStr = qqx ( curl $TimeOutStr -L $Url -o $FileName ).lines; > >> > >> > >> Many thanks, > >> -T > >> > > > On 07/28/2018 06:14 AM, Paul Procacci wrote: > > I'm not sure about qqx because I too am a fledgling perl6 programmer, > > but the run routine returns a Proc object that has an exitcode method. > > > > > > my $proc = run 'ls', 'dir!'; > > $proc.exitcode.say; > > > > > > Right in the documentation the following is stated as well: > > > > "See alsorun <https://docs.perl6.org/routine/run>andProc::Async > > <https://docs.perl6.org/type/Proc::Async>for better ways to execute > > external commands. " > > > Hi Paul, > > I adore the run command and use it very frequently. > > I this instance, I actually want to write STDERR to the > shell and only capture STDIN and the exit code. > I am trying to get "curl" to show its progress meter, > which writes to STDERR. > > So far I have > $ p6 'my $x="cat /etc/hosts; echo \$\?"; my $y = qqx ( $x ); say "$y";' > > which sends STDIN and the exit code to $y, which I can deal with. > > Thank you for the help! > > -T > -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: return code?
On Sat, Jul 28, 2018 at 4:37 AM, ToddAndMargo <mailto:toddandma...@zoho.com>> wrote: Hi All, How do I get the bash return code ("$?") from the following? $ReturnStr = qqx ( curl $TimeOutStr -L $Url -o $FileName ).lines; Many thanks, -T On 07/28/2018 06:14 AM, Paul Procacci wrote: I'm not sure about qqx because I too am a fledgling perl6 programmer, but the run routine returns a Proc object that has an exitcode method. my $proc = run 'ls', 'dir!'; $proc.exitcode.say; Right in the documentation the following is stated as well: "See alsorun <https://docs.perl6.org/routine/run>andProc::Async <https://docs.perl6.org/type/Proc::Async>for better ways to execute external commands. " Hi Paul, I adore the run command and use it very frequently. I this instance, I actually want to write STDERR to the shell and only capture STDIN and the exit code. I am trying to get "curl" to show its progress meter, which writes to STDERR. So far I have $ p6 'my $x="cat /etc/hosts; echo \$\?"; my $y = qqx ( $x ); say "$y";' which sends STDIN and the exit code to $y, which I can deal with. Thank you for the help! -T
Re: return code?
On 07/28/2018 01:37 AM, ToddAndMargo wrote: Hi All, How do I get the bash return code ("$?") from the following? $ReturnStr = qqx ( curl $TimeOutStr -L $Url -o $FileName ).lines; Many thanks, -T On 07/28/2018 01:50 AM, Benji wrote: I don't think you can with `qqx`. It returns the string output directly. You can with `run` though. my $p = run 'ls'; say $p.exitcode; Hi, I am writing exitcode down in my run notes! Thank you. I had been using $RtnCode = $proc.status; What I am trying to do is run curl and read STDIN and the return code, but leave the STDERR progress bar on the shell. I can't use "run" for this as I want the program I called to write STDERR to the shell. so far I have $ p6 'my $x="cat /etc/hosts; echo \$\?"; my $y = qqx ( $x ); say "$y";' which sends the exit code to the last line, which is pretty easy to separate from the STDIN. -T
Re: return code?
I'm not sure about qqx because I too am a fledgling perl6 programmer, but the run routine returns a Proc object that has an exitcode method. my $proc = run 'ls', 'dir!'; $proc.exitcode.say; Right in the documentation the following is stated as well: "See also run <https://docs.perl6.org/routine/run> and Proc::Async <https://docs.perl6.org/type/Proc::Async> for better ways to execute external commands. " On Sat, Jul 28, 2018 at 4:37 AM, ToddAndMargo wrote: > Hi All, > > How do I get the bash return code ("$?") from > the following? > > $ReturnStr = qqx ( curl $TimeOutStr -L $Url -o $FileName ).lines; > > > Many thanks, > -T > -- __ :(){ :|:& };:
return code?
Hi All, How do I get the bash return code ("$?") from the following? $ReturnStr = qqx ( curl $TimeOutStr -L $Url -o $FileName ).lines; Many thanks, -T