# Calling MATLAB function from Julia using the run() command

**URL:** <https://discourse.julialang.org/t/calling-matlab-function-from-julia-using-the-run-command/44299>\
**Category:** General Usage\
**Created:** [August 5, 2020, 1:13am UTC](https://discourse.julialang.org/t/calling-matlab-function-from-julia-using-the-run-command/44299 "2020-08-05T01:13:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![josimar](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@josimar](https://discourse.julialang.org/u/josimar)\
**Post date:** [August 5, 2020, 1:13am UTC](https://discourse.julialang.org/t/calling-matlab-function-from-julia-using-the-run-command/44299/1 "2020-08-05T01:13:12Z")

</div>

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 ?

```julia
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

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [August 5, 2020, 1:20am UTC](https://discourse.julialang.org/t/calling-matlab-function-from-julia-using-the-run-command/44299/2 "2020-08-05T01:20:55Z")

</div>

> **[GitHub - JuliaInterop/MATLAB.jl: Calling MATLAB in Julia through MATLAB Engine](https://github.com/JuliaInterop/MATLAB.jl)**
>
> Calling MATLAB in Julia through MATLAB Engine. Contribute to JuliaInterop/MATLAB.jl development by creating an account on GitHub.

have you tried this?

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [August 5, 2020, 4:03am UTC](https://discourse.julialang.org/t/calling-matlab-function-from-julia-using-the-run-command/44299/3 "2020-08-05T04:03:48Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)\
**Post date:** [August 5, 2020, 8:26am UTC](https://discourse.julialang.org/t/calling-matlab-function-from-julia-using-the-run-command/44299/4 "2020-08-05T08:26:01Z")

</div>

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:

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

```

or to exit Julia:

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

```

---

<div class="post-metadata">

**Author:** ![josimar](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@josimar](https://discourse.julialang.org/u/josimar)\
**Post date:** [August 6, 2020, 12:38am UTC](https://discourse.julialang.org/t/calling-matlab-function-from-julia-using-the-run-command/44299/5 "2020-08-06T00:38:17Z")

</div>

Thanks for the solution

---

<div class="post-metadata">

**Author:** ![josimar](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@josimar](https://discourse.julialang.org/u/josimar)\
**Post date:** [August 6, 2020, 12:38am UTC](https://discourse.julialang.org/t/calling-matlab-function-from-julia-using-the-run-command/44299/6 "2020-08-06T00:38:29Z")

</div>

Thanks, this solved my problem.
