Hi there, how can I create & run a command from a string, e.g.
julia> str = "echo hello world"
"echo hello world"
ERROR: IOError: could not spawn `'echo hello world'`: no such file or directory (ENOENT)
(assume str is a complex command and I’d like to perform my own escaping of arguments)
Sounds like you are thinking of a shell command? To do that you want to spawn a shell:
julia> run(`sh -c $str`);
This is the analogue of the
os.system function in Python or the
system function in C.
Of course, the whole reason why Julia’s
run commands are set up the way they are is to avoid spawning a shell and to avoid brittle manual escaping. See also this discussion: Better support for running external commands - #8 by stevengj
Could you give more context about why you are doing this?