Escaping double quotes in calling Julia from Windows command line

Hello, I’m trying to run a few Julia commands from the Windows terminal without having to manually open an instance. I’m hoping to use this command to automatically run a Julia script from Matlab, but I’m having trouble with calling cd() from the command prompt. Here’s what I get from the Windows command line:

"C:\\Users\\noconjio\\AppData\\Local\\Programs\\Julia-1.7.3\\bin\\julia" -e "println( cd(raw"U:\\eng_research_hrc_binauralhearinglab\\noconjio\\Spatial grid database\\Information coding ") |> ARGS = ["616283_SP_distances.mat"] |> include("discreteEstimator.jl"))"

ERROR: syntax: "\" is not a unary operator
Stacktrace:
 [1] top-level scope
   @ none:1

For comparison, here’s the commands within Julia I’m trying to replicate:

cd("U:\\eng_research_hrc_binauralhearinglab\\noconjio\\Spatial grid database\\Information coding\\") 
ARGS = ["616283_SP_distances.mat"]
include("discreteEstimator.jl"))"

The error suggests to me that the problem is in the double quotes used for cd(), as Julia is successfully called from the command prompt. The double quotes in the second block of code signals that the backslashes should be interpreted as part of a string, but in the first block, they seem to be wrongfully interpreted as operators, if I correctly understand it. Is there a way to fix my syntax in the println() function so that the first block of code works?

Try this:

"C:\\Users\\noconjio\\AppData\\Local\\Programs\\Julia-1.7.3\\bin\\julia" -e "println( cd(raw\"U:\\eng_research_hrc_binauralhearinglab\\noconjio\\Spatial grid database\\Information coding \") |> ARGS = [\"616283_SP_distances.mat\"] |> include(\"discreteEstimator.jl\"))"

You need to escape the " inside the julia command part.
A smaller example:

C:\Users\oheil>"julia.exe" -e "println("xxx")"
ERROR: UndefVarError: xxx not defined
Stacktrace:
 [1] top-level scope
   @ none:1

but:

C:\Users\oheil>"julia.exe" -e "println(\"xxx\")"
xxx
3 Likes

Ok, I tinkered around with you suggestion and got it to work. Here’s what I have now:

"C:\\Users\\noconjio\\AppData\\Local\\Programs\\Julia-1.7.3\\bin\\julia" -e "cd(raw\"U:\\eng_research_hrc_binauralhearinglab\\noconjio\\Spatial grid database\\Information coding\"); ARGS = [\"616283_SP_distances.mat\"]; include(\"discreteEstimator.jl\")"

I also realized |> was used to pass outputs as inputs to successive functions, when what I wanted to do was run separate lines of code as one.

I do have one last question: the Julia script I’m using also requires some distributions to work. If I use this script to run Julia from the command line, do I have to re-add the required packages?

No.
If you added the packages on the REPL using the same Julia version all is fine. The script you are including (“discreteEstimator.jl”) of course need to have lines “using packageXY” for the packages you depend on.