Re: using run
Hi Brad, Ha. Now that is exactly what I was looking for. It felt a bit clumsy having to first collect the material in a string and then print that string. This is nice. Thanks, Theo Brad Gilbert schreef op 2018-06-21 19:47: :out can take an argument ... my $fh = open 'foo.txt', :w; run 'echo', 'foo bar baz', :out($fh); close $fh; -
Re: using run
:out can take an argument On Wed, Jun 20, 2018 at 10:32 AM Theo van den Heuvel wrote: > > Hi all, > > trying to make sense of the documentation on run: > https://docs.perl6.org/routine/run. > In particular the last part. I don't understand the adverbs :out and : > err there. > Can I set it up so that the output is piped into a file directly? If so > how would I write that? > > I know I could use shell for that, but I doubt that is necessary. > > [On first reading I found the doc confusing because it start with a > hairy example. WHy would anyone wish to write to a file named > '>foo.txt'? How can that be the first example?] > my $fh = open 'foo.txt', :w; run 'echo', 'foo bar baz', :out($fh); close $fh;
Re: using run
I don't manage the docs. But a ticket has already been opened: https://github.com/perl6/doc/issues/2111 On Thu, Jun 21, 2018 at 12:59 AM Todd Chester wrote: > > > On 06/20/2018 08:58 AM, Brandon Allbery wrote: > > A pipe is for communication with a process. "Piped to a file" means > > what? What's the process you're communicating with? > > > > More to the point, "run" is intended to be lower level, specifically so > > you can directly control things. Things like redirection and shell > > pipelines are higher level. > > Hi Brandon, > > Make sure the documentation makes it clear that "run" is > not running a shell and that Pipes ("|"), redirects > ("2>&1") and such are all shell dependent. > > -T > > p.s. I almost never make a shell system call anymore. > I prefer "run" and then manipulate the data myself the > way I want to, not some awkward shell helper command. > -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: using run
On 06/20/2018 08:58 AM, Brandon Allbery wrote: A pipe is for communication with a process. "Piped to a file" means what? What's the process you're communicating with? More to the point, "run" is intended to be lower level, specifically so you can directly control things. Things like redirection and shell pipelines are higher level. Hi Brandon, Make sure the documentation makes it clear that "run" is not running a shell and that Pipes ("|"), redirects ("2>&1") and such are all shell dependent. -T p.s. I almost never make a shell system call anymore. I prefer "run" and then manipulate the data myself the way I want to, not some awkward shell helper command.
Re: using run
On 06/20/2018 08:15 AM, Theo van den Heuvel wrote: Hi all, trying to make sense of the documentation on run: https://docs.perl6.org/routine/run. In particular the last part. I don't understand the adverbs :out and : err there. Can I set it up so that the output is piped into a file directly? If so how would I write that? I know I could use shell for that, but I doubt that is necessary. [On first reading I found the doc confusing because it start with a hairy example. WHy would anyone wish to write to a file named '>foo.txt'? How can that be the first example?] Thanks, Hi Theo, There is a misunderstanding about "run". This is running a command with out a shell (sh, bash, csch. etc.). Pipes "|", redirects "2>&a" are all shell functions. So, "run" can not do any of them. But who cares! With "run" you just suck up all the data into a string, then you can do exactly what you want with it, not be relying on some helper program in the shell. Perl is 1000 times more powerful than shell commands. My favorite command is to suck up some data into a string, then do a "for" on a "split" of the string and look for what I want with match "m//" and "words" (a great grep substitute). Once you have manipulated the data yourself in Perl a few times, you will forget all about shell helper commands! Way too awkward. :-) -T
Re: using run
Hi Brandon, I used the wrong term there. I meant to say: put in a file. Sorry for the confusion. Theo Brandon Allbery schreef op 2018-06-20 17:58: If you're going to use terms in a different way than what they actually mean, it's going to be difficult to produce something that does what you believe it should do *and* what it should actually do. A pipe is for communication with a process. "Piped to a file" means what? What's the process you're communicating with? More to the point, "run" is intended to be lower level, specifically so you can directly control things. Things like redirection and shell pipelines are higher level. That said, :out and :err are incompletely documented; the form that tells it to create pipes so your script can communicate with the process is there, but you can also specify handles to attach them to. In which case you would open a file, then say :out($myHandle) to attach the process's stdout to the handle $myHandle. brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
Re: using run
El mié., 20 jun. 2018 a las 17:32, Theo van den Heuvel (< vdheu...@heuvelhlt.nl>) escribió: > Hi all, > > trying to make sense of the documentation on run: > https://docs.perl6.org/routine/run. > In particular the last part. I don't understand the adverbs :out and : > err there. > Posted as an issue to the documentation repo https://github.com/perl6/doc/issues/2111 Can I set it up so that the output is piped into a file directly? If so > how would I write that? > Comment or watch to be informed about the outcome. Of course, PRs are also welcome. JJ
Re: using run
On 06/20/2018 08:15 AM, Theo van den Heuvel wrote: Hi all, trying to make sense of the documentation on run: https://docs.perl6.org/routine/run. In particular the last part. I don't understand the adverbs :out and : err there. Can I set it up so that the output is piped into a file directly? If so how would I write that? I know I could use shell for that, but I doubt that is necessary. [On first reading I found the doc confusing because it start with a hairy example. WHy would anyone wish to write to a file named '>foo.txt'? How can that be the first example?] Thanks, Hi Theo, I wrote a module for "run" that may be useful. Let me know if you want it. It looks like this: ( RtnStr, RtnCode ) =RunNoShell( "cat --number $MyDir" ); ( RtnStr, RtnErr, RtnCode ) = RunNoShellErr( "cat --number $MyDir" ); It removes having to quote each parameter in the run string. You just write it like you were in a command shell. The returned error code ($? in bash) is really handy to have (0=true, not 0 = false in bash). It also shows what :out and :err are all about. -T
Re: using run
If you're going to use terms in a different way than what they actually mean, it's going to be difficult to produce something that does what you believe it should do *and* what it should actually do. A pipe is for communication with a process. "Piped to a file" means what? What's the process you're communicating with? More to the point, "run" is intended to be lower level, specifically so you can directly control things. Things like redirection and shell pipelines are higher level. That said, :out and :err are incompletely documented; the form that tells it to create pipes so your script can communicate with the process is there, but you can also specify handles to attach them to. In which case you would open a file, then say :out($myHandle) to attach the process's stdout to the handle $myHandle. On Wed, Jun 20, 2018 at 11:33 AM Theo van den Heuvel wrote: > Hi all, > > trying to make sense of the documentation on run: > https://docs.perl6.org/routine/run. > In particular the last part. I don't understand the adverbs :out and : > err there. > Can I set it up so that the output is piped into a file directly? If so > how would I write that? > > I know I could use shell for that, but I doubt that is necessary. > > [On first reading I found the doc confusing because it start with a > hairy example. WHy would anyone wish to write to a file named > '>foo.txt'? How can that be the first example?] > > Thanks, > > -- > Theo van den Heuvel > -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: using run
thanks. That helps Jonathan Scott Duff schreef op 2018-06-20 17:50: If you don't specify the :out adverb, then the output of the program you are running will be sent to standard output. Immediately when the program executes. If you specify the :out adverb, output from the program will be available for capture via the $proc.out method. A similar thing applies for standard error. A way to write the captured output to a file would be something like: my $proc = run 'echo', 'foo bar baz', :out; spurt("some-file-name", $proc.out.slurp(:close)); .slurp() will read all of the contents of the handle and return a string (:close closes the file handle after reading everything). spurt will write a string to a file. hope this helps, -Scott
Re: using run
If you don't specify the :out adverb, then the output of the program you are running will be sent to standard output. Immediately when the program executes. If you specify the :out adverb, output from the program will be available for capture via the $proc.out method. A similar thing applies for standard error. A way to write the captured output to a file would be something like: my $proc = run 'echo', 'foo bar baz', :out; spurt("some-file-name", $proc.out.slurp(:close)); .slurp() will read all of the contents of the handle and return a string (:close closes the file handle after reading everything). spurt will write a string to a file. hope this helps, -Scott On Wed, Jun 20, 2018 at 10:33 AM Theo van den Heuvel wrote: > Hi all, > > trying to make sense of the documentation on run: > https://docs.perl6.org/routine/run. > In particular the last part. I don't understand the adverbs :out and : > err there. > Can I set it up so that the output is piped into a file directly? If so > how would I write that? > > I know I could use shell for that, but I doubt that is necessary. > > [On first reading I found the doc confusing because it start with a > hairy example. WHy would anyone wish to write to a file named > '>foo.txt'? How can that be the first example?] > > Thanks, > > -- > Theo van den Heuvel >
Re: using run
If you're wanting to run a command and have the output go directly to a file you might want to look at shell? https://docs.perl6.org/routine/shell You can still get back a Proc object and specify if you want access to the input, output of error handles. So if you wanted to call an external command, pass it some data but have it write out to a file you can do something like this: perl6 -e 'my $p = shell "cat > foo.txt", :in;$p.in.say("test");$p.in.close()' The :in adverb says I want the in handle opened which I then write to and close :) Hope that helps. On Wed, 20 Jun 2018 at 16:32 Theo van den Heuvel wrote: > Hi all, > > trying to make sense of the documentation on run: > https://docs.perl6.org/routine/run. > In particular the last part. I don't understand the adverbs :out and : > err there. > Can I set it up so that the output is piped into a file directly? If so > how would I write that? > > I know I could use shell for that, but I doubt that is necessary. > > [On first reading I found the doc confusing because it start with a > hairy example. WHy would anyone wish to write to a file named > '>foo.txt'? How can that be the first example?] > > Thanks, > > -- > Theo van den Heuvel >
using run
Hi all, trying to make sense of the documentation on run: https://docs.perl6.org/routine/run. In particular the last part. I don't understand the adverbs :out and : err there. Can I set it up so that the output is piped into a file directly? If so how would I write that? I know I could use shell for that, but I doubt that is necessary. [On first reading I found the doc confusing because it start with a hairy example. WHy would anyone wish to write to a file named '>foo.txt'? How can that be the first example?] Thanks, -- Theo van den Heuvel