Executing External Programs in Julia
Code
In Julia, you can execute a string wrapped in backticks using the run()
function. This is similar to using os.system()
from the os
module in Python.
julia> txt = "helloworld"
"helloworld"
julia> typeof(`echo $txt`)
Cmd
As shown above, a string wrapped in backticks has the type Cmd
and can be executed with the run()
function.
julia> run(`cmd /C echo $txt`)
helloworld
Process(`cmd /C echo helloworld`, ProcessExited(0))
In this example, on Windows, you must execute echo
from the cmd
, which makes it a bit more complex. However, on Linux, you can simply use echo $txt
. If you frequently use such commands on Windows, consider modifying your environment variables1.
Environment
- OS: Windows
- julia: v1.6.3