logankilpatrick
logankilpatrick

Reputation: 14521

Calling an external command in Julia

How can I call an external command (as if I had typed it into the Windows command prompt or Unix shell) from within a Julia program? I know this is possible with other languages but I'm not sure how to do it in Julia.

Upvotes: 2

Views: 125

Answers (1)

logankilpatrick
logankilpatrick

Reputation: 14521

According to the Julia docs,

The command is never run with a shell. Instead, Julia parses the command syntax directly, appropriately interpolating variables and splitting on words as the shell would, respecting shell quoting syntax. The command is run as Julia's immediate child process, using fork and exec calls.

A simple example is as follows:

julia> testcommand = `echo HelloWorld`
`echo HelloWorld`

julia> typeof(testcommand)
Cmd

julia> run(testcommand);
HelloWorld

See the docs linked above for a deeper dive of the low-level details occurring of what is going on here.

Upvotes: 2

Related Questions