Command-line arguments: Difference between revisions

Content added Content deleted
No edit summary
(added powerbasic and visual basic; changed realbasic's lang tag to vb; minor edits to basic; alphabetized list)
Line 76: Line 76:
{{works with|FreeBASIC}}
{{works with|FreeBASIC}}


FreeBASIC supplies three ways to retrieve the arguments: <code>COMMAND$</code> (which works identically to QuickBASIC's <code>COMMAND$</code>), <code>COMMAND$()</code> (a string array which works like C's <code>argv[]</code>), and <code>__FB_ARGV__</code> (an array of pointers which works even more like C's <code>argv[]</code>).
FreeBASIC supplies three ways to retrieve the arguments: <code>COMMAND$</code> (which works identically to QuickBASIC's <code>COMMAND$</code>), <code>COMMAND$()</code> (a string array which works like [[#C|C]]'s <code>argv[]</code>), and <code>__FB_ARGV__</code> (an array of pointers which works even more like C's <code>argv[]</code>) and __FB_ARGC__ (which works like C's <code>argc</code>).


<lang freebasic>DIM i AS INTEGER
<lang freebasic>DIM i AS INTEGER
Line 104: Line 104:
arg 2 = '2'
arg 2 = '2'
arg 3 = '3'
arg 3 = '3'

See also: [[Command Line Arguments#RapidQ|RapidQ]]


=={{header|Batch File}}==
=={{header|Batch File}}==
Line 223: Line 221:
}
}
}</lang>
}</lang>

=={{header|Clean}}==
<tt>getCommandLine</tt> from the module <tt>ArgEnv</tt> returns an array of command-line arguments (the first element is the name of the program).

<lang clean>import ArgEnv

Start = getCommandLine</lang>


=={{header|Clojure}}==
=={{header|Clojure}}==
Line 241: Line 246:


All of these return a list of strings.
All of these return a list of strings.

=={{header|Clean}}==
<tt>getCommandLine</tt> from the module <tt>ArgEnv</tt> returns an array of command-line arguments (the first element is the name of the program).

<lang clean>import ArgEnv

Start = getCommandLine</lang>


=={{header|D}}==
=={{header|D}}==
Line 598: Line 596:
20
20
</pre>
</pre>

=={{header|Objective-C}}==

In addition to the regular C mechanism of arguments to main(), Objective-C also has another way to get the arguments as string objects inside an array object:
<lang objc>NSArray *args = [[NSProcessInfo processInfo] arguments];
NSLog(@"This program is named %@.", [args objectAtIndex:0]);
NSLog(@"There are %d arguments.", [args count] - 1);
for (i = 1; i < [args count]; ++i){
NSLog(@"the argument #%d is %@", i, [args objectAtIndex:i]);
}</lang>


=={{header|Objeck}}==
=={{header|Objeck}}==
Line 621: Line 609:
}
}
</lang>
</lang>

=={{header|Objective-C}}==

In addition to the regular C mechanism of arguments to main(), Objective-C also has another way to get the arguments as string objects inside an array object:
<lang objc>NSArray *args = [[NSProcessInfo processInfo] arguments];
NSLog(@"This program is named %@.", [args objectAtIndex:0]);
NSLog(@"There are %d arguments.", [args count] - 1);
for (i = 1; i < [args count]; ++i){
NSLog(@"the argument #%d is %@", i, [args objectAtIndex:i]);
}</lang>


=={{header|OCaml}}==
=={{header|OCaml}}==
Line 732: Line 730:
$second_arg = $argv[2];
$second_arg = $argv[2];
?></lang>
?></lang>

=={{header|PL/I}}==
<lang PL/I>
/* The entire command line except the command word itself is passed */
/* to the parameter variable in PL/I. */
program: procedure (command_line) options (main);
declare command_line character (100) varying;

...

end program;
</lang>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
Line 774: Line 760:
Got 'c': alpha beta
Got 'c': alpha beta
Got 'h': gamma</pre>
Got 'h': gamma</pre>

=={{header|PL/I}}==
<lang PL/I>
/* The entire command line except the command word itself is passed */
/* to the parameter variable in PL/I. */
program: procedure (command_line) options (main);
declare command_line character (100) varying;

...

end program;
</lang>


=={{header|Pop11}}==
=={{header|Pop11}}==
Line 783: Line 781:
printf(arg, '->%s<-\n');
printf(arg, '->%s<-\n');
endfor;</lang>
endfor;</lang>

=={{header|PowerBASIC}}==
For versions of PowerBASIC prior to [[PB/Win]] 9 and [[PB/CC]] 5, the only option available is identical to the one used by [[#BASIC|QuickBASIC]] above:
<lang powerbasic>? "args: '"; COMMAND$; "'"</lang>

Current versions of PowerBASIC (with the likely exception of [[PB/DOS]]) include <code>COMMAND$()</code> that works similarly to [[FreeBASIC]]'s <code>COMMAND$()</code>, except that you can't retrieve the application's name:
<lang powerbasic>'these two both return ALL args
? COMMAND$
? COMMAND$(0)

DO WHILE(LEN(COMMAND$(i)))
PRINT "The argument "; i; " is "; COMMAND$(i)
i = i + 1
LOOP</lang>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
Line 854: Line 866:


=={{header|REALbasic}}==
=={{header|REALbasic}}==
<lang vb>Function Run(args() as String) As Integer
<lang realbasic>
Function Run(args() as String) As Integer
For each arg As String In args
For each arg As String In args
Stdout.WriteLine(arg)
Stdout.WriteLine(arg)
Line 861: Line 872:
End Function</lang>
End Function</lang>
Output (given arguments: ''--foo !bar "bat bang"''):
Output (given arguments: ''--foo !bar "bat bang"''):
appName.exe
<pre>
--foo
appName.exe
!bar
--foo
bat bang
!bar
bat bang
</pre>


=={{header|REXX}}==
=={{header|REXX}}==
Line 1,077: Line 1,086:
./args.v a b c
./args.v a b c
=[args.v a b c]</lang>
=[args.v a b c]</lang>

=={{header|Visual Basic}}==

Like [[#BASIC|Qbasic]], Visual Basic returns all of the args in the built-in variable <code>Command$</code>:
<lang vb>Sub Main
MsgBox Command$
End Sub</lang>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==