How to translate bash to .bat

Well, but I cannot:

  1. launch a Julia script just by typing its name
  2. launch Julia with multiple threads from a script that runs on one thread

Sure you can. At least on Unix, you can put #!/path/to/julia at the top, exactly as you would with a shell script (to avoid having to do bash foo.sh).

Otherwise, you have to type julia foo.jl, but why is a few extra characters a big deal for a script like this?

Sure you can. As I said above, you can launch additional julia processes from a Julia script, just as you would launch julia processes from a bash script.

1 Like

Well, on Linux you can do that, but - as far as I know - not on Windows.
Furthermore the path to Julia is system dependent, and if you want to write generic code I would not know what to put there.
And as I said, it is not only about the script that creates a system image, but also about the script that launches julia and loads the correct system image…

Created a feature request: Julia should read a config file when launching · Issue #45455 · JuliaLang/julia · GitHub

Sure, on Windows you could instead write a one-line foo.bat script that runs julia foo.jl. A lot easier than porting a complicated shell script to .bat and maintaining both.

Why is easier to find the path to a .bat or .sh script than a path to Julia? Why not just put julia in your path, or a link to Julia in the directory of your script, or…?

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