Skip to content

Commit 69dd4c8

Browse files
committed
Moves run from Proc to the independent-routines page
1 parent 13afb83 commit 69dd4c8

File tree

2 files changed

+74
-73
lines changed

2 files changed

+74
-73
lines changed

doc/Type/Proc.pod6

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -145,79 +145,6 @@ your idea of a newline is.
145145
If C<$merge> is set to True, the standard output and error stream end up
146146
merged in C<$proc.out>.
147147
148-
=head2 sub run
149-
150-
Defined as:
151-
152-
=for code :method
153-
sub run(
154-
*@args ($, *@),
155-
:$in = '-',
156-
:$out = '-',
157-
:$err = '-',
158-
Bool :$bin = False,
159-
Bool :$chomp = True,
160-
Bool :$merge = False,
161-
Str:D :$enc = 'UTF-8',
162-
Str:D :$nl = "\n",
163-
:$cwd = $*CWD,
164-
Hash() :$env = %*ENV
165-
--> Proc:D)
166-
167-
Runs an external command I<without involving a shell> and returns a
168-
L<Proc|/type/Proc> object. By default, the external command will print to
169-
standard output and error, and read from standard input.
170-
171-
run 'touch', '>foo.txt'; # Create a file named >foo.txt
172-
173-
run <<rm >foo.txt>>; # Another way to use run, using word quoting for the
174-
# arguments
175-
176-
If you want to pass some variables you can still use C«< >», but try
177-
to avoid using C<« »> as it will do word splitting if you forget to
178-
quote variables:
179-
180-
my $file = ‘--my arbitrary filename’;
181-
run ‘touch’, ‘--’, $file; # RIGHT
182-
run <touch -->, $file; # RIGHT
183-
184-
run «touch -- "$file"»; # RIGHT but WRONG if you forget quotes
185-
run «touch -- $file»; # WRONG; touches ‘--my’, ‘arbitrary’ and ‘filename’
186-
run ‘touch’, $file; # WRONG; error from `touch`
187-
run «touch "$file"»; # WRONG; error from `touch`
188-
189-
Note that C<--> is required for many programs to disambiguate between
190-
command-line arguments and
191-
L<filenames that begin with hyphens|https://mywiki.wooledge.org/BashPitfalls#Filenames_with_leading_dashes>.
192-
193-
A sunk L<Proc|/type/Proc> object for a process that L<exited|/routine/exitcode>
194-
unsuccessfully will throw. If you wish to ignore such failures, simply
195-
use L<run|/routine/run> in non-sink context:
196-
197-
run 'false'; # SUNK! Will throw
198-
run('false').so; # OK. Evaluates Proc in Bool context; no sinking
199-
200-
If you want to capture standard output or error instead of having it
201-
printed directly you can use the C<:out> or C<:err> arguments
202-
respectively, which will make them available using the
203-
L<C<Proc.out>|/type/Proc> method:
204-
205-
my $proc = run 'echo', 'Perl 6 is Great!', :out, :err;
206-
$proc.out.slurp(:close).say; # OUTPUT: «Perl 6 is Great!␤»
207-
$proc.err.slurp(:close).say; # OUTPUT: «␤»
208-
209-
You can use these arguments to redirect them to a filehandle, thus
210-
creating a kind of I<pipe>:
211-
212-
my $ls-alt-handle = open :w, '/tmp/cur-dir-ls-alt.txt';
213-
my $proc = run "ls", "-alt", :out($ls-alt-handle);
214-
# (The file will contain the output of the ls -alt command)
215-
216-
These argument are quite flexible and admit, for instance, handles to
217-
redirect them. See L<Proc|/type/Proc> and
218-
L<Proc::Async|/type/Proc::Async> for more details.
219-
220-
See also L<C<new>|/type/Proc#method_new> for more examples.
221148
222149
=head2 method sink
223150

doc/Type/independent-routines.pod6

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,80 @@ spurt 'file-that-already-exists', 'new text', :createonly;
365365
# OUTPUT: «Failed to open file /home/camelia/file-that-already-exists: file already exists …»
366366
=end code
367367
368+
=head2 sub run
369+
370+
Defined as:
371+
372+
=for code :method
373+
sub run(
374+
*@args ($, *@),
375+
:$in = '-',
376+
:$out = '-',
377+
:$err = '-',
378+
Bool :$bin = False,
379+
Bool :$chomp = True,
380+
Bool :$merge = False,
381+
Str:D :$enc = 'UTF-8',
382+
Str:D :$nl = "\n",
383+
:$cwd = $*CWD,
384+
Hash() :$env = %*ENV
385+
--> Proc:D)
386+
387+
Runs an external command I<without involving a shell> and returns a
388+
L<Proc|/type/Proc> object. By default, the external command will print to
389+
standard output and error, and read from standard input.
390+
391+
run 'touch', '>foo.txt'; # Create a file named >foo.txt
392+
393+
run <<rm >foo.txt>>; # Another way to use run, using word quoting for the
394+
# arguments
395+
396+
If you want to pass some variables you can still use C«< >», but try
397+
to avoid using C<« »> as it will do word splitting if you forget to
398+
quote variables:
399+
400+
my $file = ‘--my arbitrary filename’;
401+
run ‘touch’, ‘--’, $file; # RIGHT
402+
run <touch -->, $file; # RIGHT
403+
404+
run «touch -- "$file"»; # RIGHT but WRONG if you forget quotes
405+
run «touch -- $file»; # WRONG; touches ‘--my’, ‘arbitrary’ and ‘filename’
406+
run ‘touch’, $file; # WRONG; error from `touch`
407+
run «touch "$file"»; # WRONG; error from `touch`
408+
409+
Note that C<--> is required for many programs to disambiguate between
410+
command-line arguments and
411+
L<filenames that begin with hyphens|https://mywiki.wooledge.org/BashPitfalls#Filenames_with_leading_dashes>.
412+
413+
A sunk L<Proc|/type/Proc> object for a process that L<exited|/routine/exitcode>
414+
unsuccessfully will throw. If you wish to ignore such failures, simply use
415+
L<run|/routine/run> in non-sink context:
416+
417+
run 'false'; # SUNK! Will throw
418+
run('false').so; # OK. Evaluates Proc in Bool context; no sinking
419+
420+
If you want to capture standard output or error instead of having it
421+
printed directly you can use the C<:out> or C<:err> arguments
422+
respectively, which will make them available using the
423+
L<C<Proc.out>|/type/Proc> method:
424+
425+
my $proc = run 'echo', 'Perl 6 is Great!', :out, :err;
426+
$proc.out.slurp(:close).say; # OUTPUT: «Perl 6 is Great!␤»
427+
$proc.err.slurp(:close).say; # OUTPUT: «␤»
428+
429+
You can use these arguments to redirect them to a filehandle, thus
430+
creating a kind of I<pipe>:
431+
432+
my $ls-alt-handle = open :w, '/tmp/cur-dir-ls-alt.txt';
433+
my $proc = run "ls", "-alt", :out($ls-alt-handle);
434+
# (The file will contain the output of the ls -alt command)
435+
436+
These argument are quite flexible and admit, for instance, handles to
437+
redirect them. See L<Proc|/type/Proc> and
438+
L<Proc::Async|/type/Proc::Async> for more details.
439+
440+
See also L<C<new>|/type/Proc#method_new> for more examples.
441+
368442
=head2 sub shell
369443
370444
sub shell($cmd --> Proc)

0 commit comments

Comments
 (0)