sbha
sbha

Reputation: 10422

How do I run a system command and capture the output with Julia?

How do I run a system command and capture the output with Julia?

In R I could do this with something like system_output <- system2("ls","-l", stdout=TRUE, stderr=TRUE)

Upvotes: 5

Views: 1174

Answers (1)

fredrikekre
fredrikekre

Reputation: 10984

Use the read function with a Cmd object. The docstrings are a little hard to find, so here they are:


read(command::Cmd)

Run command and return the resulting output as an array of bytes.


read(command::Cmd, String)

Run command and return the resulting output as a String.


For example, if you want to get the output of ls -l as a string, you would run

read(`ls -l`, String)

The backticks create the Cmd object, which is executed by read.

Upvotes: 14

Related Questions