# Why does the command `run` fails in this example from the documentation?

I am trying to learn how to issue shell commands from my Julia program. My OS is Windows 10 but I would also like the commands to run under Linux (Kubuntu). I found the following in the documentation:

``````julia> mycommand = `echo hello`
`echo hello`

julia> typeof(mycommand)
Cmd

julia> run(mycommand);
hello
``````

The two first commands run as displayed above, but when I try the last one I get the following:

``````julia> run(mycommand);
ERROR: IOError: could not spawn `echo hello`: no such file or directory (ENOENT)
Stacktrace:
[1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Any})
@ Base .\process.jl:99
[2] #637
@ .\process.jl:112 [inlined]
[3] setup_stdios(f::Base.var"#637#638"{Cmd}, stdios::Vector{Any})
@ Base .\process.jl:196
[4] _spawn
@ .\process.jl:111 [inlined]
[5] run(::Cmd; wait::Bool)
@ Base .\process.jl:439
[6] run(::Cmd)
@ Base .\process.jl:438
[7] top-level scope
@ REPL[19]:1

julia>
``````

I would like to understand why this happened, and more generally how to issue Windows command prompt commands like `dir`, `md`, `cd`, etc. from inside my Julia program. Same for Linux.

Any help will be greatly appreciated.

Maybe

``````; cmd /c echo hello
``````
``````julia>

shell>  cmd /c echo hello
hello
``````

The following assumes a Posix environment as on Linux or MacOS. On Windows, many similar commands, such as `echo` and `dir` , are not external programs and instead are built into the shell `cmd.exe` itself. One option to run these commands is to invoke `cmd.exe` , for example `cmd /C echo hello` . Alternatively Julia can be run inside a Posix environment such as Cygwin.

https://docs.julialang.org/en/v1/manual/running-external-programs/

1 Like