Buffer in running external program in loops

This would be wrong, right is:

run(` cmd /c "start script.bat" `)

You can use triple back ticks:
```
code
```

I mean, nothing happens and it lands in a deadlock. When I abort, the external program corresponding to ic=1 is launched in a new window.

EDIT: I reached the limit of number of posts for a new user (I know I should have created an account way earlier). Any way to avoid waiting 22 hours?

I’ll keep on editing here. In the REPL, it fails to run without any message, stg I often get when Julia meets an unexpected error it cannot handle. EDIT in EDIT: sorry, that’s when I use the shortcut “execute code and move” in VSCode, if I use include(“mycode.jl”) it leads to a deadlock as in the shell, but I can’t abort without stopping the REPL so I don’t know if the external program would ever be run.

EDIT 2: script.bat is in the current folder, I’m using

joinpath(@__DIR__,"script.bat") 

to get its absolute path.

EDIT 3: I’m working on a MWE and will keep you updated!

without anything else is not possible, I need arguments in practice…

EDIT 4: Problem solved, but not fully understood.

First, I feel sorry to have forgotten an important detail: I was not using

run(command)

but

try @spawnat :any run(command) catch; run(command) end

using non-necessary multi-threading (remnant of an earlier version to provide parallel execution for julia -and not system- code).

The problem disappeared by removing the multi-threading stuff, but why??? I could not reproduce this on my MWE (that is similar to yours). There, both the single- and multi-threaded versions work. So I dug a bit further and yes, your intuition was right, in the end the simple

run(`cmd /c "start $myexe $myinput"`)

just works fine. Basically I had the /c on the wrong side of the start in the run statement, and had to compensate by using an extra script implementing yet another start. Still what multi-threading has to do with this is a mystery we don’t need to solve. Thanks for your time and wisdom!!!

What happens if you do just this in a REPL? Is it working than?

Is script.bat in your path or in the current folder?

I need to see your code.
I suspect, that you are creating your commands using Strings and than you probably do the

`...` 

or the

Cmd(`...`) 

wrong.
Please try to create a MWE which reproduces your issue without being overly complex. My guess is, while you do this you will solve your issue by your own :wink:
MWE = minimal working example (Please read: make it easier to help you)

And I am pretty sure, that this creates an issue.
What is done with that is:
Julia exec a cmd.exe with ARGV[1]="start" and ARGV[2]="script.bat".
So cmd.exe will start interactive, runs start without parameter which fails. Now cmd as an interactive shell stalls whatever is expected to run now.
I think it would be best to just use

run(`PATH\TO\script.bat`)

without anything else. Or if this is not possible:

run(`cmd /C "start script.bat"`)

The " are important here, because
ARGV[1] must be /C and
ARGV[2] must be the whole “start script.bat

You may be able to post again, thanx to @mbauman

2 Likes