Command-line arguments: Difference between revisions
no edit summary
VincentARM (talk | contribs) (add task to aarch64 assembly raspberry pi 3) |
No edit summary |
||
(4 intermediate revisions by 4 users not shown) | |||
Line 687:
std::cout << "The argument #" << i << " is " << argv[i] << '\n';
}</syntaxhighlight>
Command line arguments are passed to main and will be converted to UTF-8 strings on all platforms.
fn void main(String[] args)
{
io::printfn("This program is named %s.", args[0]);
for (int i = 1; i < args.len; i++)
{
io::printfn("the argument #%d is %s\n", i, args[i]);
}
}</syntaxhighlight>▼
=={{header|Clean}}==
Line 1,028 ⟶ 1,044:
=={{header|Elena}}==
ELENA
<syntaxhighlight lang="elena">import system'routines;
import extensions;
Line 1,034 ⟶ 1,050:
public program()
{
program_arguments.forEvery::(int i)
{ console.printLine("Argument ",i," is ",program_arguments[i]) }
}</syntaxhighlight>
Line 1,187 ⟶ 1,203:
<pre>
The program was invoked like this => myprogram -c alpha beta -h gamma
</pre>▼
▲=={{header|Free Pascal}}==
▲<syntaxhighlight lang="pascal">
Program listArguments(input, output, stdErr);▼
Var ▼
i: integer;▼
Begin▼
writeLn('program was called from: ',paramStr(0));▼
For i := 1 To paramCount() Do▼
Begin▼
writeLn('argument',i:2,' : ', paramStr(i));▼
End;▼
End.▼
▲</syntaxhighlight>
{{out}}▼
<pre>▼
./Commandlinearguments -c "alpha beta" -h "gamma"▼
program was called from: /home/user/Documents/GitHub/rosettacode/Commandlinearguments▼
argument 1 : -c▼
argument 2 : alpha beta▼
argument 3 : -h▼
argument 4 : gamma▼
</pre>
Line 1,841 ⟶ 1,833:
for arg in commandLineParams():
echo arg</syntaxhighlight>
=={{header|Nu}}==
In Nu, the special <code>main</code> function can be declared, which gets passed the cli arguments.
<syntaxhighlight lang="nu">
def main [...argv] {
$argv | print
}
</syntaxhighlight>
▲{{out}}
▲<pre>
~> nu cli.nu A B C "Hello World!"
╭───┬──────────────╮
│ 0 │ A │
│ 1 │ B │
│ 2 │ C │
│ 3 │ Hello World! │
╰───┴──────────────╯
▲</pre>
=={{header|Oberon-2}}==
Line 1,992 ⟶ 2,002:
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">
▲Program listArguments(input, output, stdErr);
▲Var
▲ i: integer;
▲Begin
▲ writeLn('program was called from: ',paramStr(0));
▲ For i := 1 To paramCount() Do
▲ Begin
▲ writeLn('argument',i:2,' : ', paramStr(i));
▲ End;
▲End.
</syntaxhighlight>
{{out}}
<pre>
▲./Commandlinearguments -c "alpha beta" -h "gamma"
▲program was called from: /home/user/Documents/GitHub/rosettacode/Commandlinearguments
▲argument 1 : -c
▲argument 2 : alpha beta
▲argument 3 : -h
▲argument 4 : gamma
</pre>
=={{header|Perl}}==
Line 2,812 ⟶ 2,845:
=={{header|Wren}}==
This assumes that the following script,
$ wren
<syntaxhighlight lang="
System.print(Process.arguments)</syntaxhighlight>
|