🌐
The Mail Archive
mail-archive.com › perl6-all@perl.org › msg114335.html
Re: I need help with my run keeper
... https://search.brave.com/search?q=raku+what+is+:$win-verbatim-args&summary=1&conversation=245e089c41b17b4984d86e In Raku, the :$win-verbatim-args parameter is a flag used with the spawn, shell, and Proc::Async.new methods to control how command-line arguments are quoted on Windows systems.
🌐
Raku Documentation
docs.raku.org › type › Proc › Async
class Proc::Async | Raku Documentation
The :started attribute is set by ... just need to start an external program immediately. On Windows the flag $win-verbatim-args disables all automatic quoting of process arguments....
🌐
Raku Documentation
docs.raku.org › routine › run
run | Raku Documentation
It is an error to run a thread that has already been started. See primary documentation in context for sub run. ... sub run( *@args ($, *@), :$in = '-', :$out = '-', :$err = '-', Bool :$bin = False, Bool :$chomp = True, Bool :$merge = False, Str:D :$enc = 'UTF-8', Str:D :$nl = "\n", :$cwd = ...
🌐
Raku Documentation
docs.raku.org › type › Proc
class Proc | Raku Documentation
On Windows the flag $win-verbatim-args disables all automatic quoting of process arguments. See this blog for more information on windows command quoting. The flag is ignored on all other platforms.
🌐
Raku
raku.github.io › Documentable › integration-test › routine › spawn
method spawn
On Windows the flag $win-verbatim-args disables all automatic quoting of process arguments. See this blog for more information on windows command quoting. The flag is ignored on all other platforms. The flag was introduced in Rakudo version 2020.06 and is not present in older releases.
🌐
GitHub
github.com › Raku › doc › issues › 3495
Checklist for 2020.06 · Issue #3495 · Raku/doc
June 21, 2020 - If STDIN is not connected to a terminal, then Raku will read from STDIN and process that as the source of a program. The run routine, Proc.spawn and Proc::Async.new are extended with a new argument :$win-verbatim-args defaulting to False.
Published   Jun 21, 2020
🌐
The Mail Archive
mail-archive.com › perl6-all@perl.org › msg114333.html
I need help with my run keeper
I am missing what run does with (not finding them in https://docs.raku.org/routine/run) :$cwd :$env :$arg0 and :$win-verbatim-args This is what I have so far: method new(Proc:U: :$in = '-', :$out = '-', :$err = '-', Bool :$bin = False, Bool :$chomp = True, Bool :$merge = False, Str:D :$enc = 'UTF-8', Str:D :$nl = "\n", --> Proc:D) sub run( *@args ($, *@), :$in = '-', # use `:$in`, `$:out`, and `:$err` arguments to redirect to # different file handle, thus creating a kind of pipe
🌐
Perl6
docs.perl6.org › routine › run
run | Raku Documentation
Raku highlighting · sub run( *@args ($, *@), :$in = '-', :$out = '-', :$err = '-', Bool :$bin = False, Bool :$chomp = True, Bool :$merge = False, Str:D :$enc = 'UTF-8', Str:D :$nl = "\n", :$cwd = $*CWD, Hash() :$env = %*ENV, :$arg0, :$win-verbatim-args = False ·
🌐
The Mail Archive
mail-archive.com › perl6-all@perl.org › msg114408.html
Re: boo-boo in run docs?
Hi All, I do believe I came across ... https://docs.raku.org/routine/run sub run( *@args ($, *@), :$in = '-', :$out = '-', :$err = '-', Bool :$bin = False, Bool :$chomp = True, Bool :$merge = False, Str:D :$enc = 'UTF-8', Str:D :$nl = "\n", :$cwd = $*CWD, Hash() :$env = %*ENV, :$arg0, :$win-verbatim-args = False ...
Top answer
1 of 2
20

Basics

That feature is built into Raku (formerly known as Perl 6). Here is the equivalent of your Getopt::Long code in Raku:

sub MAIN ( Str  :$file    = "file.dat"
         , Num  :$length  = Num(24)
         , Bool :$verbose = False
         )
{
    $file.say;
    $length.say;
    $verbose.say;
}

MAIN is a special subroutine that automatically parses command line arguments based on its signature.

Str and Num provide string and numeric type constraints.

Bool makes $verbose a binary flag which is False if absent or if called as --/verbose. (The / in --/foo is a common Unix command line syntax for setting an argument to False).

: prepended to the variables in the subroutine signature makes them named (instead of positional) parameters.

Defaults are provided using $variable = followed by the default value.

Aliases

If you want single character or other aliases, you can use the :f(:$foo) syntax.

sub MAIN ( Str  :f(:$file)    = "file.dat"
         , Num  :l(:$length)  = Num(24)
         , Bool :v(:$verbose) = False
         )
{
    $file.say;
    $length.say;
    $verbose.say;
}

:x(:$smth) makes additional alias for --smth such as short alias -x in this example. Multiple aliases and fully-named is available too, here is an example: :foo(:x(:bar(:y(:$baz)))) will get you --foo, -x, --bar, -y and --baz and if any of them will pass to $baz.

Positional arguments (and example)

MAIN can also be used with positional arguments. For example, here is Guess the number (from Rosetta Code). It defaults to a min of 0 and max of 100, but any min and max number could be entered. Using is copy allows the parameter to be changed within the subroutine:

#!/bin/env perl6
multi MAIN
#= Guessing game (defaults: min=0 and max=100)
{
    MAIN(0, 100)
}

multi MAIN ( $max )
#= Guessing game (min defaults to 0)
{
    MAIN(0, $max)
}

multi MAIN
#= Guessing game
( $min is copy #= minimum of range of numbers to guess
, $max is copy #= maximum of range of numbers to guess
)
{
    #swap min and max if min is lower
    if $min > $max { ($min, $max) = ($max, $min) }

    say "Think of a number between $min and $max and I'll guess it!";
    while $min <= $max {
        my $guess = (($max + $min)/2).floor;
        given lc prompt "My guess is $guess. Is your number higher, lower or equal (or quit)? (h/l/e/q)" {
            when /^e/ { say "I knew it!"; exit }
            when /^h/ { $min = $guess + 1      }
            when /^l/ { $max = $guess          }
            when /^q/ { say "quiting"; exit    }
            default   { say "WHAT!?!?!"        }
        }
    }
    say "How can your number be both higher and lower than $max?!?!?";
}

Usage message

Also, if your command line arguments don't match a MAIN signature, you get a useful usage message, by default. Notice how subroutine and parameter comments starting with #= are smartly incorporated into this usage message:

./guess --help
Usage:
  ./guess -- Guessing game (defaults: min=0 and max=100)
  ./guess <max> -- Guessing game (min defaults to 0)
  ./guess <min> <max> -- Guessing game

    <min>    minimum of range of numbers to guess
    <max>    maximum of range of numbers to guess

Here --help isn't a defined command line parameter, thus triggering this usage message.

See also

See also the 2010, 2014, and 2018 Perl 6 advent calendar posts on MAIN, the post Parsing command line arguments in Perl 6, and the section of Synopsis 6 about MAIN.

2 of 2
5

Alternatively, there is a Getopt::Long for perl6 too. Your program works in it with almost no modifications:

use Getopt::Long;
my $data   = "file.dat";
my $length = 24;
my $verbose;
get-options("length=i" => $length,    # numeric
            "file=s"   => $data,      # string
            "verbose"  => $verbose);  # flag

say $length;
say $data;
say $verbose;
Find elsewhere
🌐
Raku Documentation
docs.raku.org › language › create-cli
Command line interface | Raku Documentation
If an exception is thrown that is not handled inside the MAIN sub, then the exit code will be 1. If the dispatch to MAIN failed, a usage message will be displayed on STDERR and the exit code will be 2. The command line parameters are present in the @*ARGS dynamic variable and may be altered in the mainline of the script before the MAIN unit is called.
🌐
JJA
pinguinorodriguez.cl › blog › raku-argument-parsing
Sharing command line parameters in Raku | JJA
November 11, 2020 - Raku has built-in support for writing command line interfaces. If a file has a MAIN subroutine, it will called automatically when the file is directly executed. And more interestingly will use that subroutine’s signature to automatically parse the command line arguments.
🌐
Andrewshitov
andrewshitov.com › 2018 › 12 › 20 › using-command-line-options-in-perl-6-one-liners
🎄 20/25. Using command-line options in Raku one-liners – Andrew Shitov
Welcome to Day 20 of the Perl 6 One-Liner Advent Calendar! So far, we created about 25 different one-liners, but never talked about the command-line options that the Rakudo Perl 6 compiler offers to us.
🌐
Rosetta Code
rosettacode.org › wiki › Command-line_arguments
Command-line arguments - Rosetta Code
October 1, 2025 - For this example we make a script, save to temporary directory, and call it passing arguments. We can use Win as shell substitute in M2000 environment, or the Use statement. Reading the shell statement Win we can see how the command line composed. We call the m2000.exe in the appdir$ (application directory, is the path to M2000.exe), and pass a string as a file with a path.
Top answer
1 of 2
10

So I'm guessing Zef adds it?

CompUnit::Repository::Installation adds it

Why is it there? One reason is because some wrapper needs to manage bin scripts the same name that would otherwise clash if they were in the same directory.

Is there some way to use the run-script method shown above without Zef?

run-script is for CompUnit::Repository::Installation only -- if you aren't installing a module then run-script won't be of interest

Assuming I do need to have my users download two files, where should I have them install the files?

Well the recommended/idiomatic way would be to use the core raku functionality to install things (i.e. use zef). Otherwise where you should put some code is either a) not going to matter or b) going to be mostly dependendant on your environment, what is idiomatic for your os, etc.

Does it need to be copied into their Raku module search path (and, if so, what command would show them what that path is)

echo $RAKULIB should suffice for showing the module search path in most cases, especially if they aren't interested in where the installation paths are. And as such you can instruct users to set e.g. RAKULIB=$FROB_LIB_DIR to point wherever your library is if you want them to be able to run your script without manually specifying it via raku -I../ frobnicate (so they don't copy the code anywhere special, they just point to wherever they e.g. clone your repo). Ditto for working with $PATH.

Or can I modify the frobnicate wrapper in some way (maybe by changing raku to raku -Ilib or something like that?) in a way that would let them install both to directory on their PATH?

I would advise against installing things based on some value in $PATH. Instruct users to set $PATH, don't install things to $PATH.

Technically you could add use lib '../' to your script, but using use lib in a script that you also want users to install normally is less than ideal since its adding an unused, potentially hijackable module search path when being run from such an install.

If you want your code to precompile then I suggest putting it in a module, and instructing your users that, if they don't intent to install it, to invoke it via raku -I../ ./frobnicate on a per-use basis or something like export RAKULIB="$FROB_LIB_DIR,$RAKULIB" followed by ./frobnicate for something more permanent. Alternatively if someone evenetually implements precompilation of scripts then you could just use the single file approach.

2 of 2
5

Some comments on this topic.

  1. It is optimal, I think, to use zef because zef will also load dependencies. It is already unusual to be able to write a Raku program without using other modules and I would expect this to become even more unusual as more Raku modules get developed.

  2. I forget which modules I have installed on my system, and included in a program. By specifying everything in META6.json, then running zef test ., the chance of ensuring someone else can download the module is improved. Actually, I have found the best way to ensure this is to create a docker file and try to install a new module in a docker image/container - but that's another topic.

  3. I have found (for Linux, and I cannot comment about Windows) that if I:

    • write an executable in Raku (see below), lets call it MyWonder,
    • place it in the <distribution>/bin folder,
    • give it +x permission(s), and
    • specify it in the distribution's root META6.json file
    • (publish the distribution)

    then when zef installs the distribution, MyWonder will work on the command line (assuming that zef itself works on the command line, implying that PATH contains the directory to zef).

  4. The optimal (for me) way of invoking a program that is meant to be used on command line, or invoked by a desktop, is:

    • put the following into the MyWonder file (no need for extension)
    use v6.d;
    use MyWonderLife;
    
    • put all of the functionality into MyWonderLife.rakumod
    • make sure there is at least one sub MAIN in MyWonderLife.rakumod
    • specify MyWonderLife in the META6.json file (which allows a lot of flexibility about which directory you can put the actual MyWonderLife.rakummod file under; it doesn't have to be lib/)
    • create a simple test t/basic.rakutest for the distribution, with just the test use-ok 'MyWonderLife;

    This recipe means that all the functionality is precompiled by zef, so that when the executable is called by the user, there is a much quicker response. The slowest part when using Raku is compiling a program. By installing with zef, this is done once during installation. Programs in all languages are slow to install, so a Raku program does not cause a user to wonder what is happening at the moment it is being used.

    Secondly, it is possible to use several multi sub MAIN to handle a variety of calling situations, and to use the range of command line options that can now be handled. Whilst this is obviously possible in any script, putting them all in a .rakumod file seems (to me) to be more natural.

    I've found that extensive tests are a pain to watch when modules are being installed, so I have begun to move most of the development and maintenance testing to xt/ and only have simple installation tests in t/.

    Finally, with this recipe (and assuming you have given the distribution the name MyWonderLife in the META6.json file, the installation instructions for MyWonder, assuming it is possible to call the program with no arguments are simply:

    Use zef to install MyWonderLife, eg.,

    zef install MyWonderLife
    

    and use it on a Command Line as follows:

    MyWonder
    
🌐
Raku Guide
raku.guide
Raku Guide
If a function is allowed to run through it’s block to the end, the last statement or expression will determine the return value. ... For the sake of clarity, it might be a good idea to explicitly specify what we want returned. This can be done using the return keyword. ... In one of the previous examples, we saw how we can restrict the accepted argument to be of a certain type.
🌐
Andrewshitov
andrewshitov.com › 2018 › 10 › 31 › working-with-files-and-directories-in-perl-6
📘 Working with files and directories in Raku – Andrew Shitov
By default, either a new destination file will be created or rewritten if it already exists. You can open the file in the append mode by adding the :append value in the third argument:
🌐
Andrewshitov
andrewshitov.com › 2018 › 10 › 31 › slurpy-parameters-and-flattening-in-perl-6
📘 Slurpy parameters and flattening in Raku – Andrew Shitov
Its grammar, syntax, sigils, and ... 6 as Raku. You are reading the article written before the rename. What is said here, most likely still works, but you may want considering to review the differences after the rename. The texts published on this site prior to the rename will stay unchanged for reflecting the historical truth. Perl 6 allows passing scalars, arrays, hashes, or objects of any other type as the arguments to a ...
🌐
Raku Documentation
docs.raku.org › routine › MAIN
MAIN | Raku Documentation
The sub with the special name MAIN will be executed after all relevant entry phasers (BEGIN, CHECK, INIT, PRE, ENTER) have been run and the mainline of the script has been executed. No error will occur if there is no MAIN sub: your script will then just have to do the work, such as argument ...