popen3 - Kill a process called using open3 in ruby -


I am using a command line program, it is mentioned below:

  $ ROUTE_TO_FOLDER / App & lt; "Long text"   

If the "long text" parameter is written using the requirement "app" , then it If the file with a result will fill a text, then it will fill the text file with consistent dots (I can not handle or modify the "app" to avoid it).

There is a line like this in the Ruby script:

  text = "long text to be used by the app" output = system ("ROUTE_TO_FOLDER / app & lt; # {text} ")   

Now, if the text is written well then problems will not occur and I will get an output file as explained earlier. The problem occurs when the text is good It is not written in the way that what happens next is that my ruby ​​script is hanging and I am not sure that it is Sector kill.

I have found and I have used the method like this:

  IRB & gt; CMD = "ROUTE_TO_FOLDER / App & lt; # {text}" irb & gt; Stdin, stdout, stderr, wait_thr = open 3.popen3 (cmd) = & gt; [# & Lt; IO: FD10>, & lt; IO: FD 11 & gt;, & lt; IO: FD 13 & gt;, & lt; Thread: 0x007f3a1a6f8820 runs>]   

When I do:

  irb & gt; Wait_thr.value   

This is also hanging, and:

  irb> Wait_thr.status = & gt; "Sleep"   

So .. how can I avoid these problems? Is not it a realization that the "app" has failed?

Thank you in advance

wait_thr.pid Start the PIN of the process started just do it

  process Kill ("kill", wait_thr.pid)   

when you have to kill it.

Set a time-frame to wait for this process:

  can combine with determining that the process is suspended in two ways (Continuous output dots).  
  Obtain '/ process' text = "Make long text which will be used by app" cmd = "ROUTE_TO_FOLDER / app" and "# {text}" Open3.popen3 (cmd). I, o, e, w | Start timeout. Timeout (10) Set # timeout to 10 seconds, if required # Process Output of the process. When this is done, the EOF will be produced until the OEF? Do # o.read_nonblock (N) ... end end rescue timeout :: error # You know that the process takes process more than 10 seconds. Kill ("kill", w.pid) # End the end of any other error processing you need.   

2) Check the process output. (The code below has been simplified - you probably do not want to read the output of your process before and in the process of a string buff, and I think you get this idea).

  get '/ process' text = "long text which will be used by app" cmd = "ROUTE_TO_FOLDER / app"; # {text} "Open3.popen3 (cmd) | process # of process output i.o., when it is done, eof output will be # if you receive 16 dots in line - the process is in continuous loop # (You want to deal with stderr instead - where is it sent on the basis of point) buf = "error" false until OEF? Do buf & lt; O.read_nonblock (16 ) If buf.size & gt; = 16 & amp; buf [-16 ..-1] == '.' * 16 # OK, the process has been processed. Kill ("Kelly", PPID) Error = True # You should also get the OEO? Next time you check (or after flushing the pipes) , Then you will reach the OEO? Loop end time if error ############################################################################

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -