Command-line arguments: Difference between revisions
added powerbasic and visual basic; changed realbasic's lang tag to vb; minor edits to basic; alphabetized list
No edit summary |
(added powerbasic and visual basic; changed realbasic's lang tag to vb; minor edits to basic; alphabetized list) |
||
Line 76:
{{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|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
Line 104:
arg 2 = '2'
arg 3 = '3'
=={{header|Batch File}}==
Line 223 ⟶ 221:
}
}</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}}==
Line 241 ⟶ 246:
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}}==
Line 598 ⟶ 596:
20
</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}}==
Line 621 ⟶ 609:
}
</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}}==
Line 732 ⟶ 730:
$second_arg = $argv[2];
?></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}}==
Line 774 ⟶ 760:
Got 'c': alpha beta
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}}==
Line 783 ⟶ 781:
printf(arg, '->%s<-\n');
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}}==
Line 854 ⟶ 866:
=={{header|REALbasic}}==
<lang vb>Function Run(args() as String) As Integer▼
▲Function Run(args() as String) As Integer
For each arg As String In args
Stdout.WriteLine(arg)
Line 861 ⟶ 872:
End Function</lang>
Output (given arguments: ''--foo !bar "bat bang"''):
appName.exe▼
--foo▼
▲appName.exe
!bar▼
▲--foo
bat bang▼
▲!bar
▲bat bang
=={{header|REXX}}==
Line 1,077 ⟶ 1,086:
./args.v a b c
=[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}}==
|