F#以编程方式运行.fsx脚本文件 [英] F# programmatically running .fsx script file

查看:153
本文介绍了F#以编程方式运行.fsx脚本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定这一定很容易,但是我似乎无法使它生效.假设我有一个.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆