带参数运行 f# 脚本

Ole*_*rov 9 f#-interactive fsi

我尝试通过批处理文件使用 fsi.exe 运行 f# 脚本

CALL "path\fsi.exe" --quiet --exec --use:"path\FindAndDelete.fsx" arg1 arg2 arg3
Run Code Online (Sandbox Code Playgroud)

我需要我的脚本程序与 arg1 arg2 和 arg3 一起运行。但是命令:

for arg in Environment.GetCommandLineArgs() do
    printfn "%s" arg
Run Code Online (Sandbox Code Playgroud)

打印所有参数并说 arg1 是错误参数,但我只需要在脚本中使用 arg1、arg2、arg3 进行操作。尽管运行带有参数的 f# 脚本并使用它们进行操作的最佳方法是什么?

Vor*_*ato 10

我个人使用 fsi.CommandLineArgs。第 0 个参数是文件名,因此您可以使用 Array.tai​​l 来获取参数。

let args : string array = fsi.CommandLineArgs |> Array.tail
let first = args.[0]
let second = args.[1]
Run Code Online (Sandbox Code Playgroud)

或者,如果您决定使用 GetCommandLineArgs(),则第一个参数看起来是列表中的第四个元素,即 args。[3]

fsi --exec outputGetCommandlineArgs.fsx 哇耶不

输出

[|"pathtofsi\fsi.exe"; "--exec"; "outputGetCommandlineArgs.fsx"; "woah"; "yay"; "no"|]
Run Code Online (Sandbox Code Playgroud)