简体   繁体   中英

Starting f# interactive with Process.Start

So I stripped the code down to what doesn't work, which is what follows:

[<EntryPoint>]
let main argv = 
  let procStart = new ProcessStartInfo(argv.[0], argv.[1..] |> String.concat " ")
  procStart.RedirectStandardInput <- true
  let proc = Process.Start(argv.[0], argv.[1..] |> String.concat " ")
  let y = Console.ReadLine()
  0

So I started the program with the command line arguments "fsi". fsi is f# interactive, which is on my path, so I'm assuming the absolute path doesn't matter. The program started fine, then it started the fsi process, which started up and shut down after displaying a red error for a split second. I couldn't read the error that fast, so I print screened to get a picture, so there may be a typo or two, but here is the error:

unknown(1,1): error FSI1223: FSharp.Core.sigdata not found alongside FSharp.Core


unknown(1,1): error FS0229: Error opening binary file 'Path\to\project\bin\debug\FSharp.Core': Exception of type 'Microsoft.FSharp.Compiler.ErrorLogger+StopProcessing was thrown.

There was a little bit more about not being able to read the f#.core assembly.

My theory is this: I can start fsi from a normal cmd window; I'm thinking that when I start fsi from cmd, it looks in the same directory as fsi to find f#.core, but when I start it with Process.Start it looks in the current directory for some reason.

I don't know if I'm right, and I don't know how to fix this even if I am.

我不确定为什么会这样,但是您可以通过将ProcessStartInfo.WorkingDirectory属性设置为fsi本身所在的位置来解决。

Fyoder gave me the clue to the solution, so I accepted his answer, but it was not quite clear enough.

The issue is that fsi and the parent process are trying to use FSharp.Core.dll, which will crash fsi . fsi looks in the current directory first to find the dll, and it finds it, so it assumes it will be ok to use. When `fsi is invoked in a directory that doesn't have the dll, it works fine because it finds the one in the fsi folder.

This should explain why ProcessStartInfo.WorkingDirectory fixes the issue. Note that you can set it to any folder that does not have FSharp.Core.dll in it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM