develooper Front page | perl.perl6.users | Postings from June 2018

Re: using run

Thread Previous
From:
Simon Proctor
Date:
June 20, 2018 15:44
Subject:
Re: using run
Message ID:
CAGwa-jjp0Qf97Y4GRUUaJ4F_9zECKitfX7_WKiYQhHjbSX5gQw@mail.gmail.com
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 <vdheuvel@heuvelhlt.nl>
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
>

Thread Previous


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