F # programmatically works .fsx script file

I am sure that this should be something very simple, but I cannot get it to work. Let's say I have a .fsx script file and you want it to execute programmatically. I assume that someone should have blogged about this at some point, but I cannot find an example that runs my simple script. Basically, I want to programmatically duplicate what happens when you right-click on a .fsx file and select "Run with F # Interactive ..."

+6
source share
2 answers

As stated in the comment, you can set UseShellExecute to false so as not to open the Windows shell. This way you can get your output directly in the 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 
+2
source

After a random mess with the args command line, I finally got it to work. I feel a little lame in answering my own question, but hopefully it helps someone else anyway. It turned out that I was mistaken in the correct use of command line arguments. If someone has something more elegant or even useful than what I put, I will give you an answer.

 open System.Diagnostics let launchExecutable() = let proc = new Process() proc.StartInfo.FileName <- @"C:\Program Files (x86)\Microsoft F#\v4.0\fsi.exe" proc.StartInfo.Arguments <- @"--exec --nologo pathToFSXFile\Test.fsx" proc.Start() launchExecutable();; 
+1
source

Source: https://habr.com/ru/post/885775/


All Articles