How can I use Windows cmd from within Julia?

Viewed 348

I’m trying to call cmd commands via Julia in Windows. According to multiple examples I've seen, including the official documentation, this should be as easy placing the command in backticks and then executing it using run.

For example:

mycommand = `dir`
run( mycommand )

But when I try this I get an error:

ERROR: LoadError: IOError: could not spawn `dir`: no such file or directory (ENOENT)

To me the error indicates that Julia is looking for a file named dir and does not attempt to execute it as a command in cmd.

What am I doing wrong? How do I tell Julia that this is a command that is to be executed in the terminal and not a file?

1 Answers

Use

run(`cmd /c dir`)

as cmd.exe is the executable you need to run.

Related