Question

I have a bunch of F# scripts (fsx) that I use for my basic deployment needs. I just right click them and say "Run with F# interactive"

However, sometimes the script fails and I would like to keep the interactive console running. So far I haven't figured out a nice way to achieve that.

I tried starting up the fsi.exe manually but then how can I launch my script from there?

Was it helpful?

Solution

If you are hackish enough, you may want adding just another Explorer context menu item similar to Run with F# Interactive, but keeping the console window open after .fsx script terminates. Here is the working outline of how to achieve this for Windows7/VS2012:

  • being admin open regedit and find the key HKEY_CLASSES_ROOT\VisualStudio.fsx.11.0\shell
  • add new subkey with some unique name, like openRunCmd, make (Default) value for this key whatever you like to see in context menu, maybe Run with Fsi in shell
  • finally, add subkey HKEY_CLASSES_ROOT\VisualStudio.fsx.11.0\shell\openRunCmd\command and set (Default) value for this subkey to the following line:

    c:\windows\system32\cmd.exe /Q /K %%USERPROFILE%%\fsx.bat "%1"

Now, close regedit, go to your home directory and create there a batch file fsx.bat with the following line:

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

After these mods you would be able to click on any .fsx script with right mouse button, pick Run with Fsi in shell and have the shell window staying after script termination until you close it. With few small adjustments the same approach would work for VS2010.

Just be careful to adjust details, if your system settings differ from ones above. Good luck!

Update: For those who want to try this at home or at work I've posted a detailed walk-through here.

OTHER TIPS

#load "myScipt.fsx";;

should work I think. But myself i prefer just to have separate console window (cmd.exe), from which i can run fsi myScipt.fsx and see the output.

I have created a windows shortcut with

Target:

cmd /k "C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\Fsi.exe" deploy.fsx

Start in:

C:\FolderContaningFsxScript

This keeps the window open if the script fails so I can see any compile errors. It also keeps the window open if the script runs successfully which might or might not be desirable.

I find it easier to just click the shortcut instead of Right Click > Run with F# Interactive. I think a batch file with the above command would work as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top