Class: HandBrake::CLI::PopenRunner
- Inherits:
-
Object
- Object
- HandBrake::CLI::PopenRunner
- Defined in:
- lib/handbrake/cli.rb
Overview
The default runner. Uses IO.popen
to spawn
HandBrakeCLI. General use of this library does not require
monkeying with this class.
If you have non-general use case, a replacement runner must have a method matching the signature of #run.
Instance Method Summary collapse
-
#command(arguments) ⇒ String
The concatentated command string to pass to IO.popen.
-
#initialize(cli_instance) ⇒ PopenRunner
constructor
A new instance of PopenRunner.
- #run(arguments) ⇒ RunnerResult
Constructor Details
#initialize(cli_instance) ⇒ PopenRunner
Returns a new instance of PopenRunner.
323 324 325 |
# File 'lib/handbrake/cli.rb', line 323 def initialize(cli_instance) @cli = cli_instance end |
Instance Method Details
#command(arguments) ⇒ String
Returns the concatentated command string to pass to IO.popen.
362 363 364 |
# File 'lib/handbrake/cli.rb', line 362 def command(arguments) "'#{arguments.unshift(@cli.bin_path).collect { |a| a.gsub(%r(')) { %('\\\'') } }.join("' '")}' 2>&1" end |
#run(arguments) ⇒ RunnerResult
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/handbrake/cli.rb', line 340 def run(arguments) output = '' cmd = command(arguments) $stderr.puts "Spawning HandBrakeCLI using #{cmd.inspect}" if @cli.trace? if @cli.dry_run? puts cmd RunnerResult.new('', 0) else IO.popen(cmd) do |io| while line = io.read(60) output << line $stderr.write(line) if @cli.trace? end end RunnerResult.new(output, $?) end end |