I am want to run a system command (executing a file) from inside a code written in Julia. However, writing
run(`echo Hello`)
throws an error
could not spawn `echo Hello`: no such file or directory (ENOENT)
in run at base\process.jl:650
in #spawn#374 at base\process.jl:511
in setup_stdio at base\process.jl:499
in #375 at base\process.jl:512
in _jl_spawn at base\process.jl:360
More questions on the same subject. I am in Windows
I wish to execute a batch file, say
C:\path\web.bat
If I double click on the file in Windows-Explorer, the file executes correctly. If I execute
run(`cmd /c C:\\path\\web.bat`)
it fails. I believe this is because it is executed from Julia’s home directory, and the batch file does not find some dependencies.
So my question, how do I get Julia to run
a) cd C:\path
b) web.bat
If I just write
run(`cmd /c cd C:\\path\\webapp`)
run(`cmd /c web.bat`)
things fail: 'web.bat' is not recognized as an internal or external command, operable program or batch file. I believe because the “current directory” is lost from on run command ot the next. How can I get run to execute a sequence of commands?
(Not sure about Windows-specific concerns to do with cmd, but at least for the path handling part…) The current working directory is inheritied from Julia each time cmd is invoked. Therefore, you need to move Julia’s working directory and then run the command, not change directory inside a command which is going to end. One way to do this without actually changing Julia’s working directory forever is to do it temporarily like
cd("C:\\path\\webapp") do
run(`cmd /c web.bat`)
end