Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run f# script with parameters

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?

like image 854
Olexiy Pyvovarov Avatar asked Sep 30 '22 06:09

Olexiy Pyvovarov


1 Answers

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"|]
like image 180
VoronoiPotato Avatar answered Oct 06 '22 02:10

VoronoiPotato