F# programmatically running .fsx script file

后端 未结 2 481
猫巷女王i
猫巷女王i 2020-12-31 23:49

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 prog

2条回答
  •  梦毁少年i
    2021-01-01 00:05

    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
    

提交回复
热议问题