Calling MATLAB function from Julia using the run() command

I am trying to call a MATLAB function from Julia but I am getting the error below. There is something wrong with the way that I am setting up the quotes.

In the context of my problem below, I don’t know how to interpret the following message:

special characters "#{}()[]<>|&*?~;" must be quoted in commands

Could someone help me to find out what is happening ?

run(`$matlabExec -nodesktop -nodisplay -r 'MyMatlabCode()';exit()`)
ERROR: LoadError: parsing command `$matlabExec -nodesktop -nodisplay -r 'MyMatlabCode()';exit()`: special characters "#{}()[]<>|&*?~;"
must be quoted in commands
Stacktrace:
 [1] error(::String) at .\error.jl:33
 [2] shell_parse(::String, ::Bool; special::String) at .\shell.jl:100
 [3] @cmd(::LineNumberNode, ::Module, ::Any) at .\cmd.jl:389
in expression starting at none:1

have you tried this?

I have no idea about matlab, but in general, either do as the error message says and quote special characters exit\(\) or just use string interpolation:

mycmd = "MyMatlabCode(); exit()"
run(`$matlabExec -nodesktop -nodisplay -r $mycmd`)
2 Likes

Your code wouldn’t work either way because $matlabExec -nodesktop -nodisplay -r 'MyMatlabCode()';exit() gets interpreted as

  1. run $matlabExec -nodesktop -nodisplay -r 'MyMatlabCode()'
  2. run exit()

in that order.

You either want to add exit() to what Matlab has to run:

run(`$matlabExec -nodesktop -nodisplay -r 'MyMatlabCode();exit()'`)

or to exit Julia:

run(`$matlabExec -nodesktop -nodisplay -r 'MyMatlabCode()'`)
exit()
1 Like

Thanks for the solution

Thanks, this solved my problem.