8
8
class Proc::Async {}
9
9
= end code
10
10
11
- B < Note: > only the MoarVM backend of Rakudo implements C < Proc::Async > at the
12
- moment.
11
+ B < Note: > only the MoarVM backend of Rakudo implements C < Proc::Async > at
12
+ the moment.
13
13
14
- C < Proc::Async > allows you to run external commands asynchronously, capturing
15
- standard output and error handles, and optionally write to its standard input.
14
+ C < Proc::Async > allows you to run external commands asynchronously,
15
+ capturing standard output and error handles, and optionally write to its
16
+ standard input.
16
17
17
18
= begin code
18
19
my $file = ‘foo’.IO;
@@ -127,18 +128,20 @@ An example of piping several commands like C<echo "Hello, world" | cat -n>:
127
128
multi method new(*@ ($path, *@args), :$w, :$enc, :$translate-nl --> Proc::Async:D)
128
129
multi method new( :$path, :@args, :$w, :$enc, :$translate-nl --> Proc::Async:D)
129
130
130
- Creates a new C < Proc::Async > object with external program name or path C < $path >
131
- and the command line arguments C < @args > .
131
+ Creates a new C < Proc::Async > object with external program name or path
132
+ C < $path > and the command line arguments C < @args > .
132
133
133
134
If C < :w > is passed to C < new > , then a pipe to the external program's standard
134
135
input stream (stdin) is opened, to which you can write with C < write > and
135
136
C < say > .
136
137
137
- The C < :enc > specifies L < the encoding|/type/IO::Handle#method_encoding > for streams
138
- (can still be overridden in individual methods) and defaults to C < utf8 > .
138
+ The C < :enc > specifies L < the encoding|/type/IO::Handle#method_encoding >
139
+ for streams (can still be overridden in individual methods) and defaults
140
+ to C < utf8 > .
139
141
140
- If C < :translate-nl > is set to C < True > (default value), OS-specific newline
141
- terminators (e.g. C < \r\n > on Windows) will be automatically translated to C < \n > .
142
+ If C < :translate-nl > is set to C < True > (default value), OS-specific
143
+ newline terminators (e.g. C < \r\n > on Windows) will be automatically
144
+ translated to C < \n > .
142
145
143
146
= head2 method stdout
144
147
@@ -186,8 +189,9 @@ along as L<Str|/type/Str>.
186
189
await $promise;
187
190
188
191
You must call C < stderr > before you call L < #method start > . Otherwise an
189
- exception of class L < X::Proc::Async::TapBeforeSpawn|/type/X::Proc::Async::TapBeforeSpawn > is
190
- thrown.
192
+ exception of class
193
+ L < X::Proc::Async::TapBeforeSpawn|/type/X::Proc::Async::TapBeforeSpawn >
194
+ is thrown.
191
195
192
196
If C < stderr > is not called, the external program's standard error stream is not
193
197
captured at all.
@@ -203,8 +207,8 @@ Use L«C<.Supply>|/type/Proc::Async#method_Supply» for merged STDOUT and STDERR
203
207
multi method bind-stdin(IO::Handle:D $handle)
204
208
multi method bind-stdin(Proc::Async::Pipe:D $pipe)
205
209
206
- Sets a handle (which must be opened) or a C < Pipe > as a source of C < STDIN > . The C < STDIN > of
207
- the target process must be writable or
210
+ Sets a handle (which must be opened) or a C < Pipe > as a source of
211
+ C < STDIN > . The C < STDIN > of the target process must be writable or
208
212
C < X::Proc::Async::BindOrUse > will be thrown.
209
213
210
214
my $p = Proc::Async.new("cat", :in);
@@ -223,16 +227,18 @@ and will print the content of C</etc/profile> to standard output.
223
227
224
228
method bind-stdout(IO::Handle:D $handle)
225
229
226
- Redirects STDOUT of the target process to a handle (which must be opened).
227
- If STDOUT is closed L < X::Proc::Async::BindOrUse|/type/x/proc/async/BindOrUse >
228
- will be thrown.
230
+ Redirects STDOUT of the target process to a handle (which must be
231
+ opened). If STDOUT is closed
232
+ L < X::Proc::Async::BindOrUse|/type/x/proc/async/BindOrUse > will be
233
+ thrown.
229
234
230
235
my $p = Proc::Async.new("ls", :out);
231
236
my $h = "ls.out".IO.open(:w);
232
237
$p.bind-stdout($h);
233
238
$p.start;
234
239
235
- This program will pipe the output of the C < ls > shell command to a file called C < ls.out > , which we are opened for reading.
240
+ This program will pipe the output of the C < ls > shell command to a file
241
+ called C < ls.out > , which we are opened for reading.
236
242
237
243
= head2 method bind-stderr
238
244
@@ -416,8 +422,8 @@ The C<Proc::Async> object must be created for writing (with
416
422
C < Proc::Async.new(:w, $path, @args) > ). Otherwise an
417
423
L < X::Proc::Async::OpenForWriting > exception will the thrown.
418
424
419
- C < start > must have been called before calling method close-stdin, otherwise an
420
- L < X::Proc::Async::MustBeStarted > exception is thrown.
425
+ C < start > must have been called before calling method close-stdin,
426
+ otherwise an L < X::Proc::Async::MustBeStarted > exception is thrown.
421
427
422
428
= head2 method kill
423
429
0 commit comments