Run f# script with parameters

2k views Asked by At

I try to run f# script using fsi.exe via batch file

CALL "path\fsi.exe" --quiet --exec --use:"path\FindAndDelete.fsx" arg1 arg2 arg3

I need my script program operate with arg1 arg2 and arg3. But the command:

for arg in Environment.GetCommandLineArgs() do
    printfn "%s" arg

prints all the parameters and say that arg1 is wrong parameter,but I need to operate only with arg1, arg2,arg3 in my script. Although what is the best way to run f# script with parameters and operate with them?

1

There are 1 answers

0
VoronoiPotato On

I personally use fsi.CommandLineArgs. The 0th argument is the filename so you can use Array.tail to get the args.

let args : string array = fsi.CommandLineArgs |> Array.tail
let first = args.[0]
let second = args.[1]

Alternatively if you do decide to use GetCommandLineArgs() it looks like the first argument is the 4th element in the list, aka args.[3]

fsi --exec outputGetCommandlineArgs.fsx woah yay no

outputs

[|"pathtofsi\fsi.exe"; "--exec"; "outputGetCommandlineArgs.fsx"; "woah"; "yay"; "no"|]