Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line arguments in F# program?

Tags:

.net

f#

How can I get command line arguments in F# compiled program? Is it possible if I don't use default template with

[<EntryPoint>]
let Main(args) = ...

I've tried

let args = Sys.argv

and

let args = fsi.CommandLineArgs

but it doesn't work for me :-(

like image 230
Nik Avatar asked Jun 14 '13 16:06

Nik


People also ask

What are the arguments in command line?

Command-line arguments are given after the name of the program in command-line shell of Operating Systems. To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.

What is command line arguments in oops?

A command-line argument is an information that directly follows the program's name on the command line when it is executed. To access the command-line arguments inside a Java program is quite easy. They are stored as strings in the String array passed to main( ).

What are command line arguments in C explain?

Command-line arguments are simple parameters that are given on the system's command line, and the values of these arguments are passed on to your program during program execution. When a program starts execution without user interaction, command-line arguments are used to pass values or files to it.


1 Answers

If you don't want to use the args array passed to your main function then you could use System.Environment.GetCommandLineArgs() instead. Note this will include the name of the program being run as the first item, unlike the args array given to your main function.

open System

[<EntryPoint>]
let main(args) =    
    printfn "args: %A" args
    printfn "env.cmdline: %A" <| Environment.GetCommandLineArgs()    
    0

Run as args.exe 1 2 3 4:

args: [|"1"; "2"; "3"; "4"|]
env.cmdline: [|"args.exe"; "1"; "2"; "3"; "4"|]
like image 55
Leaf Garland Avatar answered Sep 19 '22 02:09

Leaf Garland