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

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

问题描述

我确信这一定是一件非常简单的事情,但我似乎无法让它发挥作用.假设我有一个 .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屋!

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