new creates a new Proc object, whereas run or shell create one and spawn it with the command and arguments provided in @args or $cmd, respectively.

$in, $out and $err are the three standard streams of the to-be-launched program, and default to "-" meaning they inherit the stream from the parent process. Setting one (or more) of them to True makes the stream available as an IO::Pipe object of the same name, like for example $proc.out. You can set them to False to discard them. Or you can pass an existing IO::Handle object (for example IO::Pipe) in, in which case this handle is used for the stream.

Please bear in mind that the process streams reside in process variables, not in the dynamic variables that make them available to our programs. Thus, modifying the dynamic filehandle variables (such as $*OUT) inside the host process will have no effect in the spawned process, unlike $*CWD and $*ENV, whose changes will be actually reflected in it.

my$p-name="/tmp/program.p6";

my$program=Q:to/END/;

#!/usr/bin/env perl6

$*OUT.say( qq/\t$*PROGRAM: This goes to standard output/ );

END

spurt$p-name, $program;

$*OUT.put:"1. standard output before doing anything weird";

{

temp$*OUT=open'/tmp/out.txt', :w;

$*OUT.put:"2. temp redefine standard output before this message";

shell( "perl6 $p-name" ).so;

}

$*OUT.put:"3. everything should be back to normal";

# OUTPUT

# 1. standard output before doing anything weird

# /tmp/program.p6: This goes to standard output

# 3. everything should be back to normal

# /tmp/out.txt will contain:

# 2. temp redefine standard output before this message

This program shows that the program spawned with shell is not using the temporary $*OUT value defined in the host process (redirected to /tmp/out.txt), but the initial STDOUT defined in the process.

$bin controls whether the streams are handled as binary (i.e. Blob object) or text (i.e. Str objects). If $bin is False, $enc holds the character encoding to encode strings sent to the input stream and decode binary data from the output and error streams.

With $chomp set to True, newlines are stripped from the output and err streams when reading with lines or get. $nl controls what your idea of a newline is.

If $merge is set to True, the standard output and error stream end up merged in $proc.out.

Runs the Proc object with the given command and environment which are passed through to the shell for parsing and execution. See shell for an explanation of which shells are used by default in the most common operating systems.