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.