exe should run when i am open the page. Asynchronous process need to run.
Is there any way for run exe Asynchronously with two arguments in ruby?
i have tried ruby commands - system() , exec() but its waiting the process complete. i need to start exe with parameter no need to wait for the process complete
is any rubygems going to support for my issue?
You can use Process.spawn
and Process.wait2
:
pid = Process.spawn 'your.exe', '--option'
# Later...
pid, status = Process.wait2 pid
Your program will be executed as a child process of the interpreter. Besides that, it will behave as if it had been invoked from the command line.
You can also use Open3.popen3
:
require 'open3'
*streams, thread = Open3.popen3 'your.exe', '--option'
# Later...
streams.each &:close
status = thread.value
The main difference here is that you get access to three IO
objects. The standard input, output and error streams of the process are redirected to them, in that order.
This is great if you intend to consume the output of the program, or communicate with it through its standard input stream. Text that would normally be printed on a terminal will instead be made available to your script.
You also get a thread which will wait for the program to finish executing, which is convenient and intuitive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With