F#以编程方式运行.fsx脚本文件 [英] F# programmatically running .fsx script file
问题描述
我敢肯定这一定很容易,但是我似乎无法使它生效.假设我有一个.fsx
脚本文件,并希望使其以编程方式执行.我猜想某人一定在某个时候写过博客,但是我似乎找不到能够执行我的简单场景的示例.基本上,我想以编程方式复制右键单击.fsx
文件并选择使用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 Files\Microsoft F#\v4.0\Fsi.exe")
psi.Arguments <- script
psi.UseShellExecute <- false
let p = Process.Start(psi)
p.WaitForExit()
p.ExitCode
这篇关于F#以编程方式运行.fsx脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!