Run(cmd) manual examples throw error

In the examples from the manual section “Running External Programs”, I can’t seem to get the examples to work on my machine…

cmd = `echo hello`
run(cmd)

Here is the error:

ERROR: IOError: could not spawn `echo hello`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(::String, ::Cmd, ::Array{Any,1}) at .\process.jl:99
 [2] #550 at .\process.jl:112 [inlined]
 [3] setup_stdios(::Base.var"#550#551"{Cmd}, ::Array{Any,1}) at .\process.jl:196
 [4] _spawn at .\process.jl:111 [inlined]
 [5] run(::Cmd; wait::Bool) at .\process.jl:439
 [6] run(::Cmd) at .\process.jl:438
 [7] top-level scope at REPL[9]:1

What am I missing?

Looks like you are using Windows, and presumable there is no echo program to spawn.

I am using windows - but if I put echo hello into the windows command prompt I receive expected echo?

It is probably a shell builtin then and not a separate program. Try cmd /c echo hello.

1 Like

This prints hello as expected if I run it in cmd.exe, but if I use it as a command object in julia like so

cmd = `"""cmd /c echo hello"""`
run(cmd)

I receive the same error as above?

You shouldn’t have those """s there:

julia> run(`cmd /c echo hello`)
hello
Process(`cmd /c echo hello`, ProcessExited(0))
2 Likes

Many thanks!