0

I have a ruby script that midway through I need it to run another program.

After running the program the rest of the script doesnt get run. For example:

# some ruby that gets run

exe = "Something.exe"
system(exe)

# some ruby that doesnt run

I have also tried using Open3.popen2e(cmd) and Open3.popen3(cmd) but its the same.

Can anyone help me understand what is happening here and how to fix it?

note: I'm using windows

Brad
  • 8,044
  • 10
  • 39
  • 50
  • Does your Something.exe complete its execution? It seems like if your ruby script is waiting for the command to be completed before to continue – mabe02 Sep 13 '17 at 16:04
  • The program stay running in the background, so really i dont want ruby to wait, i just want it to send the command and carry on. – Brad Sep 13 '17 at 16:06

2 Answers2

2

Try to run Something.exe in a new Thread:

Thread.new { system("Something.exe") }

thaleshcv
  • 752
  • 3
  • 7
1

In case you want to run your System.exe asynchronously and continue without waiting it to be finished, you could use spawn or multithreading.

pid = spawn('System.exe')
Process.detach(pid)

According to this previous answer, this should work on Windows as well (while fork or other methods don't).

In this article you can find several examples using system, exec, fork, spawn and Thread on Unix.

I cannot reproduce it, but it could be worth to see if using system("start System.exe") works on windows like system("cmd &") works on UNIX. You can refer to start documentation here.

mabe02
  • 2,676
  • 2
  • 20
  • 35