Execute external program in ruby and wait for its execution

Sebastian Müller picture Sebastian Müller · Jul 11, 2011 · Viewed 10.9k times · Source

How do I start an external program (like an excel sheet) from ruby and wait for its execution resp. termination before continuing.

I know I can start the excel sheet with

system 'start excel "my/path/to/the/sheet"' 

but using this will only start the sheet and then continues.

Answer

Jonathan picture Jonathan · Jul 11, 2011

The problem you are having is not with Ruby but the start command, this launches another program and returns immediately. You need to make that command wait for excel to finish using the wait flag:

system('start /wait excel "my/path/to/the/sheet"')