Executing External Programs in Julia
Code
In Julia, the run()
function is used to execute a string wrapped in backticks `. This is similar to using the os.system()
from the os
module in Python.
julia> txt = "helloworld"
"helloworld"
julia> typeof(`echo $txt`)
Cmd
위와 같이 백틱으로 감싸진 문자열은 Cmd
라는 타입을 가지고, run()
함수로써 실행할 수 있다.
julia> run(`cmd /C echo $txt`)
helloworld
Process(`cmd /C echo helloworld`, ProcessExited(0))
Limited to this example, on Windows, it becomes a bit complicated as you have to execute echo
within cmd
, but on Linux, you can simply use echo $txt
. If you frequently use such commands on Windows, consider modifying the environment variables1.
Environment
- OS: Windows
- julia: v1.6.3