Sha256: 7461161caf0910a557659334cfa8ff019faf4b8838c1ce0a6461c4b3252fdfbb

Contents?: true

Size: 1.31 KB

Versions: 21

Compression:

Stored size: 1.31 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
      
      # seems that pipe cannot handle non-ascii characters right on windows (even with correct encoding)  
      consoleOutput.gsub!(/\xE2\x80\x98/,"`") # ÔÇÿ
      consoleOutput.gsub!(/\xE2\x80\x99/,"'") # ÔÇÖ
      
      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
    
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
cxxproject-0.6.28 lib/cxxproject/utils/process.rb
cxxproject-0.6.27 lib/cxxproject/utils/process.rb
cxxproject-0.6.26 lib/cxxproject/utils/process.rb
cxxproject-0.6.25 lib/cxxproject/utils/process.rb
cxxproject-0.6.24 lib/cxxproject/utils/process.rb
cxxproject-0.6.23 lib/cxxproject/utils/process.rb
cxxproject-0.6.21 lib/cxxproject/utils/process.rb
cxxproject-0.6.18 lib/cxxproject/utils/process.rb
cxxproject-0.6.17 lib/cxxproject/utils/process.rb
cxxproject-0.6.14 lib/cxxproject/utils/process.rb
cxxproject-0.6.12 lib/cxxproject/utils/process.rb
cxxproject-0.6.13 lib/cxxproject/utils/process.rb
cxxproject-0.6.11 lib/cxxproject/utils/process.rb
cxxproject-0.6.10 lib/cxxproject/utils/process.rb
cxxproject-0.6.9 lib/cxxproject/utils/process.rb
cxxproject-0.6.6 lib/cxxproject/utils/process.rb
cxxproject-0.6.5 lib/cxxproject/utils/process.rb
cxxproject-0.6.4 lib/cxxproject/utils/process.rb
cxxproject-0.6.2 lib/cxxproject/utils/process.rb
cxxproject-0.6.1 lib/cxxproject/utils/process.rb