Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonforums/811728 to your computer and use it in GitHub Desktop.
Save jonforums/811728 to your computer and use it in GitHub Desktop.
figuring out MRI and JRuby's use of system()
C:\Users\Jon\Documents\RubyDev\sandbox>jruby --1.9 -Xlaunch.inproc=false system_ruby.rb --start
[INFO] doing some work via system()...
jruby 1.6.0.RC2 (ruby 1.9.2 patchlevel 136) (2011-02-09 5434c72) (Java HotSpot(TM) Client VM 1.6.0_24) [Windows 7-x86-java]
[INFO] OK, I'm back from the working case.
[INFO] playing with processes via system()...
[INFO] starting 1st system using '--start' style
*** FAIL: both hang with 1st system after starting .exe, never return ***
C:\Users\Jon\Documents\RubyDev\sandbox>jruby --1.9 -Xlaunch.inproc=false system_ruby.rb --cmd-start
[INFO] doing some work via system()...
jruby 1.6.0.RC2 (ruby 1.9.2 patchlevel 136) (2011-02-09 5434c72) (Java HotSpot(TM) Client VM 1.6.0_24) [Windows 7-x86-java]
[INFO] OK, I'm back from the working case.
[INFO] playing with processes via system()...
[INFO] starting 1st system using '--cmd-start' style
*** FAIL: both hang with 1st system after starting .exe, never return ***
C:\Users\Jon\Documents\RubyDev\sandbox>jruby --1.9 -Xlaunch.inproc=false system_ruby.rb --popen
[INFO] doing some work via system()...
jruby 1.6.0.RC2 (ruby 1.9.2 patchlevel 136) (2011-02-09 5434c72) (Java HotSpot(TM) Client VM 1.6.0_24) [Windows 7-x86-java]
[INFO] OK, I'm back from the working case.
[INFO] playing with processes via system()...
[INFO] starting 1st system using '--popen' style
[INFO] back from 1st system; starting 2nd system
*** FAIL ***
5434c72: did not start .exe; required CTRL-C to exit
c813123: started .exe but never returned from 1st system
C:\Users\Jon\Documents\RubyDev\sandbox>jruby --1.9 -Xlaunch.inproc=false system_ruby.rb --popen-start-str
[INFO] doing some work via system()...
jruby 1.6.0.RC2 (ruby 1.9.2 patchlevel 136) (2011-02-09 5434c72) (Java HotSpot(TM) Client VM 1.6.0_24) [Windows 7-x86-java]
[INFO] OK, I'm back from the working case.
[INFO] playing with processes via system()...
[INFO] starting 1st system using '--popen-start-str' style
org/jruby/RubyIO.java:3675:in `popen19': Cannot run program "start" (in directory "C:\
Users\Jon\Documents\RubyDev\sandbox"): CreateProcess error=2, The system cannot find t
he file specified (IOError)
from system_ruby.rb:32:in `fails'
from system_ruby.rb:71:in `(root)'
*** FAIL ***
C:\Users\Jon\Documents\RubyDev\sandbox>jruby --1.9 -Xlaunch.inproc=false system_ruby.rb --popen-args
[INFO] doing some work via system()...
jruby 1.6.0.RC2 (ruby 1.9.2 patchlevel 136) (2011-02-09 5434c72) (Java HotSpot(TM) Client VM 1.6.0_24) [Windows 7-x86-java]
[INFO] OK, I'm back from the working case.
[INFO] playing with processes via system()...
[INFO] starting 1st system using '--popen-args' style
[INFO] back from 1st system; starting 2nd system
*** FAIL ***
5434c72: required CTRL-C to exit
c813123: did not start .exe but completed
C:\Users\Jon\Documents\RubyDev\sandbox>ruby system_ruby.rb --start
[INFO] doing some work via system()...
ruby 1.9.2p180 (2011-02-18 revision 30907) [i386-mingw32]
[INFO] OK, I'm back from the working case.
[INFO] playing with processes via system()...
[INFO] starting 1st system using '--start' style
[INFO] back from 1st system; starting 2nd system
[INFO] back from 2nd system; starting 3rd system
ruby 1.9.2p180 (2011-02-18 revision 30907) [i386-mingw32]
[INFO] back from 3rd system; starting final system
[INFO] back from final system
[INFO] OK, I'm back from the failing case.
*** PASS ***
C:\Users\Jon\Documents\RubyDev\sandbox>ruby system_ruby.rb --cmd-start
[INFO] doing some work via system()...
ruby 1.9.2p180 (2011-02-18 revision 30907) [i386-mingw32]
[INFO] OK, I'm back from the working case.
[INFO] playing with processes via system()...
[INFO] starting 1st system using '--cmd-start' style
[INFO] back from 1st system; starting 2nd system
[INFO] back from 2nd system; starting 3rd system
ruby 1.9.2p180 (2011-02-18 revision 30907) [i386-mingw32]
[INFO] back from 3rd system; starting final system
[INFO] back from final system
[INFO] OK, I'm back from the failing case.
*** PASS ***
C:\Users\Jon\Documents\RubyDev\sandbox>ruby system_ruby.rb --popen
[INFO] doing some work via system()...
ruby 1.9.2p180 (2011-02-18 revision 30907) [i386-mingw32]
[INFO] OK, I'm back from the working case.
[INFO] playing with processes via system()...
[INFO] starting 1st system using '--popen' style
[INFO] back from 1st system; starting 2nd system
[INFO] back from 2nd system; starting 3rd system
ruby 1.9.2p180 (2011-02-18 revision 30907) [i386-mingw32]
[INFO] back from 3rd system; starting final system
[INFO] back from final system
[INFO] OK, I'm back from the failing case.
*** FAIL: hang with 1st system; never returned ***
C:\Users\Jon\Documents\RubyDev\sandbox>ruby system_ruby.rb --popen-start-str
[INFO] doing some work via system()...
ruby 1.9.2p180 (2011-02-18 revision 30907) [i386-mingw32]
[INFO] OK, I'm back from the working case.
[INFO] playing with processes via system()...
[INFO] starting 1st system using '--popen-start-str' style
[INFO] back from 1st system; starting 2nd system
[INFO] back from 2nd system; starting 3rd system
ruby 1.9.2p180 (2011-02-18 revision 30907) [i386-mingw32]
[INFO] back from 3rd system; starting final system
[INFO] back from final system
[INFO] OK, I'm back from the failing case.
*** PASS ***
C:\Users\Jon\Documents\RubyDev\sandbox>ruby system_ruby.rb --popen-args
[INFO] doing some work via system()...
ruby 1.9.2p180 (2011-02-18 revision 30907) [i386-mingw32]
[INFO] OK, I'm back from the working case.
[INFO] playing with processes via system()...
[INFO] starting 1st system using '--popen-args' style
*** FAIL: hang with 1st system; never returned ***
# usage:
#
# 0) i only like windows systems
# 1) download and extract Process Monitor zip from
# http://technet.microsoft.com/en-us/sysinternals/bb896645
# 2) edit 'exe' to match Process Monitor install
# 3) manually run 'procmon.exe' once to accept EULA
# 4) 'ruby system_ruby.rb' or 'jruby [--1.9] -Xlaunch.inproc=false system_ruby.rb'
# from an administrator command prompt
require 'rubygems'
$exe = 'c:/winsystools/ProcessMonitor/procmon.exe'
$log_dir = ENV['temp'] || ENV['tmp']
$log_file = File.expand_path(File.join($log_dir, 'api_trace.pml'))
def works(options={})
system("#{Gem.ruby} #{options[:niner]} #{options[:jruby_inproc]} -ve \"\"")
end
def fails(options={})
puts "[INFO] starting 1st system using '#{options[:style]}' style"
base_cmd = "/quiet /minimized /backingfile #{$log_file}"
case options[:style]
when '--start'
system("start #{$exe} #{base_cmd}")
when '--cmd-start'
system("cmd /c start #{$exe} #{base_cmd}")
when '--popen'
IO.popen("#{$exe} #{base_cmd}", 'r+') { |io| }
when '--popen-start-str'
IO.popen("start #{$exe} #{base_cmd}", 'r+') { |io| }
when '--popen-args'
IO.popen(["#{$exe}", "#{base_cmd}"], 'r+') { |io| }
end
puts '[INFO] back from 1st system; starting 2nd system'
system("#{$exe} /waitforidle")
puts '[INFO] back from 2nd system; starting 3rd system'
system("#{Gem.ruby} #{options[:niner]} #{options[:jruby_inproc]} -ve \"\"")
puts '[INFO] back from 3rd system; starting final system'
system("#{$exe} /terminate")
puts '[INFO] back from final system'
end
if __FILE__ == $0
opts = {}
opts[:style] = ARGV.delete('--start') ||
ARGV.delete('--cmd-start') ||
ARGV.delete('--popen') ||
ARGV.delete('--popen-args') ||
ARGV.delete('--popen-start-str')
unless opts[:style]
abort '[ERROR] must provide --start, --cmd-start, --popen, --popen-args, or --popen-start-str'
end
if RUBY_PLATFORM =~ /java/i
opts[:niner] = '--1.9'
opts[:jruby_inproc] = '-Xlaunch.inproc=false'
end
puts '[INFO] doing some work via system()...'
works(opts)
puts "[INFO] OK, I'm back from the working case."
puts '[INFO] playing with processes via system()...'
fails(opts)
puts "[INFO] OK, I'm back from the failing case."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment