How to translate bash to .bat

Registering a julia script file type/extension in Windows

Suggested here → How to write a program as a Julia package? - #26 by MA_Laforge
repo here → GitHub - ma-laforge/JuliaScripting.jl

In short, Windows allows you to register a file type, say *.jl_script to be executed with Julia in order to run. A sample file could be:

#!JLScript -iq --startup-file=no --project=@SomeGlobalEnvironment
using ModuleFrom_SomeGlobalEnvironment

result = ModuleFrom_SomeGlobalEnvironment.run_important_tasks()
display(result)

:DONE

Comments

  • (Doesn’t actually need to use some global environment - but practical in terms of getting a stable Julia run environment)
  • In the working example I provided, I pattern mach #!JLScript and pass the remaining arguments to the julia command.
  • But if you want to be cross-compatible with how Linux shell scripts work, this could be changed to match some #!/path/to/julia pattern instead to match what @stevengj suggested to make julia scripts runnable on Unix/Linux.

What already works

  • Automatically loads the script using the desired, CLEAN, environment (starts with a clean JULIA_LOAD_PATH - see install_files/launch_julia_script.ps1.).
  • Right now, my code *auto-registers an “Excecute with Julia vX” Exprlorer menu item for the .jl_script type (though I’m pretty certain I am using Win-XP Legacy registry settings).
  • You can launch .jl_script files using RMB from explorer.

*auto-registers: when you call JuliaScripting.install()

image

What’s missing.

  • Probably would be better to use newer methodology/registry settings if you are better at deciphering MS docs than I am.
  • If you can figure out how to make this “Execute with Julia vX” item the default: then executing any .jl_script file from PowerShell or cmd will automatically run the script as intended.

Try it out for yourself: You can launch any .txt file from Windows PowerShell by typing in its the file name at the prompt. Doing so gets windows to figure out which “default program/action” to use to launch the .txt file.

2 Likes