lib/vagrant/util/subprocess.rb in vagrant-unbundled-1.9.1.1 vs lib/vagrant/util/subprocess.rb in vagrant-unbundled-1.9.5.1

- old
+ new

@@ -23,20 +23,39 @@ end def initialize(*command) @options = command.last.is_a?(Hash) ? command.pop : {} @command = command.dup - @command = @command.map { |s| s.encode(Encoding.default_external) } @command[0] = Which.which(@command[0]) if !File.file?(@command[0]) if !@command[0] raise Errors::CommandUnavailableWindows, file: command[0] if Platform.windows? raise Errors::CommandUnavailable, file: command[0] end @logger = Log4r::Logger.new("vagrant::util::subprocess") end + # @return [TrueClass, FalseClass] subprocess is currently running + def running? + !!(@process && @process.alive?) + end + + # Stop the subprocess if running + # + # @return [TrueClass] FalseClass] true if process was running and stopped + def stop + if @process && @process.alive? + @process.stop + true + else + false + end + end + + # Start the process + # + # @return [Result] def execute # Get the timeout, if we have one timeout = @options[:timeout] # Get the working directory @@ -60,10 +79,10 @@ notify_table[:stdout] = notify.include?(:stdout) notify_stdin = notify.include?(:stdin) # Build the ChildProcess @logger.info("Starting process: #{@command.inspect}") - process = ChildProcess.build(*@command) + @process = process = ChildProcess.build(*@command) # Create the pipes so we can read the output in real time as # we execute the command. stdout, stdout_writer = ::IO.pipe stderr, stderr_writer = ::IO.pipe