Gordon
Gordon

Reputation: 113

F# Script Ends Immediately After Execution (FSI)

When I double-click .fsx files the script ends immediately after execution. There is no chance of interacting with the script or see what it does.

I can barely see one of the scripts create a WinForms window, but it quickly closes.

I have tried several default Run actions (including sending to a .cmd file):

"C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\fsi.exe" "%1" %*
"C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\fsi.exe" --quiet --exec "%1"

Upvotes: 2

Views: 226

Answers (1)

Tarmil
Tarmil

Reputation: 11372

Both command lines you tried do indeed run the script and then exit. If you want to keep the REPL open to interact with the script, you need either --load:file.fsx or --use:file.fsx.

  • --use:file.fsx does roughly the same as just running fsi and then pasting the contents of file.fsx into the REPL. So for example if the file just contains let x = 2 then you can immediately type x;; and it will be recognized. This is the one you want if your file contains a bunch of values, statements, types and/or modules.

  • --load:file.fsx does roughly the same as just running fsi and typing #load "file.fsx". This means that values defined in this file will be in a separate namespace. This is the one you want if your file starts with a namespace or module declaration.

Upvotes: 2

Related Questions