Method: SensibleSwing::MainWindow#system_blocking

Defined in:
lib/gui/base.rb

#system_blocking(command, low_prio = false) ⇒ Object



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/gui/base.rb', line 361

def system_blocking command, low_prio = false
  return true if command =~ /^@rem/ # JRUBY-5890 bug
  if low_prio
    out = IO.popen(command) # + " 2>&1"
    low_prio = 64 # from msdn
    
    if command =~ /(ffmpeg|mencoder)/
      # XXXX not sure if there's a better way...because some *are* complex and have ampersands...
      # unfortunately have to check for nil because it could exit too early [?]
      exe_name = $1 + '.exe'
      begin
        p = proc{ ole = ::WMI::Win32_Process.find(:first,  :conditions => {'Name' => exe_name}); sleep 1 unless ole; ole }
        piddy = p.call || p.call || p.call # we actually do need this to loop...guess we're too quick
        # but the first time through this still inexplicably fails all 3...odd
        piddys = ::WMI::Win32_Process.find(:all,  :conditions => {'Name' => exe_name})
        for piddy in piddys
          # piddy.SetPriority low_prio # this call can seg fault at times...JRUBY-5422
          pid = piddy.ProcessId # this doesn't seg fault, tho
          system_original("vendor\\setpriority -lowest #{pid}") # uses PID for the command line
        end
      rescue Exception => e
        p 'warning, got exception trying to set priority [jruby prob? ...]', e
      end
    end
    print out.read # let it finish
    out.close
    $?.exitstatus == 0 # 0 means success
  else
    raise command + " failed env #{ENV['PATH']}" unless system_original command
  end
end