Can't run local command on Windows

Something in the PATH works (e.g.):

run(`git submodule update --init --recursive $smName`)

where smName is a string defined previously.

But, when I want to run a script in a directory, something like

run(`./bootstrap`)

or

run(`.\\bootstrap`)

where either one of those works calling it in a cmd or powershell window. I get

ERROR: LoadError: could not spawn `./bootstrap`: no such file or directory (ENOENT)

or (respectively)

ERROR: LoadError: could not spawn `'.\bootstrap'`: no such file or directory (ENOENT)

The latter error presents another problem (because quoting the command won’t run the command). It still shouldn’t fail, however, because running that single-quoted string in powershell returns the quoted string back to you:

> '.\bootstrap'
.\bootstrap

So, what am I doing wrong here? FYI, it works perfectly on linux.

Is bootstrap a windows batch file? (.bat or .cmd)
Then try with the file extension.
run(`bootstrap.cmd`)

libuv is not capable of spawning batch files directly.

The quoting of commands in printing isn’t done in a way that is appropriate for windows cmd. That could be fixed, though cmd’s quoting rules are very complicated and it may be better to avoid it entirely.

@greg_plowman: That one in particular is, but I need to be able to run local .exe programs as well. So, I need a general solution.

@tkelman: Is there a way to manually specify using powershell or git bash even, instead of cmd?

something like

run(`powershell -Command "./bootstrap"`)

should work

1 Like

@tkelman: Thanks. That works fine.

On the other hand, if people want to treat Julia as a scripting language, the Cmd functions should work cross-platform without extra code. Julia should make jump through this kind of hoop instead of the programmer. I know that’s probably asking a lot (I’ve seen a little of the discussion around this on the issue tracker), but from a user’s perspective, that’s basic scripting functionality.

If it’s possible for you to always specify the extension, then it should work:

run(`program1.exe`)
run(`program2.com`)
run(`script1.bat`)
run(`script2.cmd`)

@greg_plowman: That doesn’t work on linux, though. You have to give the “./”

OK, seems like you want something to work for Windows and Linux (without using if is_windows() or similar).
Not sure if this is currently possible since Windows will require file extensions for .bat and .cmd files, and these are unlikely to be names on Linux.

Note that run(`.\\program.[exe|com|bat|cmd]`) will work on Windows.

Also if you already have a string cmdname appropriate for the OS, then the following should work for both Windows and Linux:

cmdpath = joinpath(".", cmdname)
run(`$cmdpath`)