Re: What are values with : called?

[email protected] (ToddAndMargo via perl6-users) Sun, 2 Nov 2025 20:29:39 -0800
Newsgroups perl.perl6.users
Message-ID <[email protected]>
On 11/2/25 7:13 PM, Bruce Gray wrote:
> 
> 
>> On Nov 2, 2025, at 20:31, ToddAndMargo via perl6-users <[email protected]> wrote:
>>
>> On 11/2/25 4:55 PM, Joseph Brenner wrote:
>>>         my $proc = run 'echo', 'Raku is Great!', :out, :err;
>>>         $proc.out.slurp(:close).say; # OUTPUT: «Raku is Great!␤»
>>>         $proc.err.slurp(:close).say; # OUTPUT: «␤»
>>
>> Hi Joseph,
>>
>> The default of both :out and :err is "-",
>> which is STDOUT and STDERR.  This is
>> similar to curl's "--output -" which send
>> to the STDOUT.
>>
>> What I find puzzling is where else would they
>> be going?
> 
> They (STDOUT and STDERR) would be going to the standard filehandles of the *parent* process, just like if you run a command inside a Bash script.
> The parent in this case is Raku itself, so they would go to your screen, or wherever you have redirect all the Raku STDOUT and/or STDERR to.
> 
> % raku -e '
>      say "raku talks to STDOUT";
>      run(|<ls -d .>);
>      note "raku talks to STDERR";
>      run(|<ls fake>);
>      ' > a.txt 2>b.txt
> 
> % cat a.txt
>      raku talks to STDOUT
>      .
> 
> % cat b.txt
>      raku talks to STDERR
>      ls: fake: No such file or directory
>      The spawned command 'ls' exited unsuccessfully (exit code: 1, signal: 0)
>        in block <unit> at -e line 5
> 
> 
> 
>> Can I modify :out to :out("eraseme.txt") and
>> have the output go to a file (eraseme.txt)
>> instead of STDOUT?  That would be kind of cool.
>>
>> Yours in puzzlement,
>> -T
> 
> `:out` can take a argument, but it needs a filehandle, not a filename.
> It you want to open it in-line, it must be a *writable* filehandle, so this will not work:
> 	:out("eraseme.txt".IO)
> Instead, use this:
> 	:out("eraseme.txt".IO.open(:w))
> or, open the filehandle separately, potentially to use it across several `run` commands, then close it manually.
> 


Hi Bruce,

I am slowly catching on.

:out and :err set to "-" are "capturing" the STDOUT and
STDERR to $p.out and $p.err.  Otherwise they go to your
console/shell.

And if you want to alter then, your need to provide
and file handle.

Thank you!
-T