F# 以编程方式运行 .fsx 脚本文件 [英] F# programmatically running .fsx script file
问题描述
我确信这一定是一件非常简单的事情,但我似乎无法让它发挥作用.假设我有一个 .fsx
脚本文件并希望以编程方式执行它.我猜一定有人在某个时候写过关于这个的博客,但我似乎找不到一个例子来执行我的简单场景.基本上,我想以编程方式复制当您右键单击 .fsx
文件并选择Run with F# Interactive..."
I'm sure this must be something really easy, but I can't seem to make it work. Let's say I have an .fsx
script file and want to cause it to be executed programmatically. I'm guessing someone must have blogged about this at some point, but I can't seem to find an example that performs my simple scenario. Basically, I want to programmatically duplicate what happens when you right click on an .fsx
file and choose "Run with F# Interactive..."
推荐答案
如评论中所问,您可以将 UseShellExecute
设置为 false 以避免打开 Windows shell.这样,您就可以直接在 F# shell 中输出:
As asked in a comment, you can set UseShellExecute
to false to avoid opening the Windows shell. This way, you can have your output directly in F# shell:
open System.Diagnostics
let execScript script =
let psi = new ProcessStartInfo(@"c:Program FilesMicrosoft F#v4.0Fsi.exe")
psi.Arguments <- script
psi.UseShellExecute <- false
let p = Process.Start(psi)
p.WaitForExit()
p.ExitCode
这篇关于F# 以编程方式运行 .fsx 脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!