Sha256: 18d7af6ecdfb47ce64bcf110d4532eaaf4d1648fafe8b94cb8a8920eafeea24e
Contents?: true
Size: 1.53 KB
Versions: 6
Compression:
Stored size: 1.53 KB
Contents
module Cxxproject class ProcessHelper @@pid = nil def self.readOutput(sp, rd, wr) wr.close consoleOutput = "" begin while not rd.eof? tmp = rd.read(1000) if (tmp != nil) consoleOutput << tmp end end rescue Exception=>e # Seems to be a bug in ruby: sometimes there is a bad file descriptor on Windows instead of eof, which causes # an exception on read(). However, this happens not before everything is read, so there is no practical difference # how to "break" the loop. # This problem occurs on Windows command shell and Cygwin. end Process.wait(sp) rd.close consoleOutput.encode!('UTF-8', :invalid => :replace, :undef => :replace, :replace => '') consoleOutput.encode!('binary', :invalid => :replace, :undef => :replace, :replace => '') consoleOutput end def self.spawnProcess(cmdLine) return system(cmdLine) if Cxxproject::Utils.old_ruby? @@pid = spawn(cmdLine) pid, status = Process.wait2(@@pid) @@pid = nil status.success? end def self.killProcess begin Process.kill("KILL",@@pid) rescue end @@pid = nil end def self.safeExecute begin consoleOutput = yield [($?.to_i >> 8) == 0, consoleOutput, false] rescue Exception => e [false, e.message, true] end end end end
Version data entries
6 entries across 6 versions & 1 rubygems