# Groking system() on Windows

**URL:** <https://www.ruby-forum.com/t/groking-system-on-windows/202747>\
**Category:** JRuby\
**Created:** [February 4, 2011, 10:25pm UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747 "2011-02-04T22:25:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 4, 2011, 10:25pm UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/1 "2011-02-04T22:25:25Z")

</div>

I’m trying to use system() from JRuby 1.6.0.RC1 on Windows to integrate  
with Process Monitor [1] to do some WinAPI tracing for performance  
comparisons. The actual code lives at [2] but I’ve got a test case that  
shows the issue at [figuring out MRI and JRuby's use of system() · GitHub](https://gist.github.com/811728)

Basically, I want to start up procmon.exe and immediately return. Call  
procmon again and tell it to wait. Fire up JRuby to run some code (line  
24) to be traced by procmon and return when the test code completes.  
After that’s all done, tell procmon to terminate.

Charlie has either blogged or posted to ruby-core on calling  
jruby-from-jruby and, IIRC, the punchline is that JRuby does some  
optimizations so that things run in the same JRuby process. The problem  
I’m having is that it appears that line 24 in the gist never returns  
from the system() call and I’m guessing the reason is that it was run in  
the existing JRuby process.

While the MRI and JRuby behavior is different (appears to hang on JRuby)  
I just want to understand JRuby’s behavior better and find a better  
solution than the one I’m currently using to trace how the different  
impl’s use WinAPI calls to do things like read large files line-by-line  
and other things.

A working case on MRI looks like…

C:\Users\Jon\Documents\RubyDev\sandbox\>ruby system\_ruby.rb  
[INFO] doing some work via system()…  
ruby 1.9.2p174 (2011-01-28 revision 30696) [i386-mingw32]  
[INFO] OK, I’m back.  
[INFO] playing with processes via system()…  
ruby 1.9.2p174 (2011-01-28 revision 30696) [i386-mingw32]  
[INFO] OK, I’m back.

…and the failing case on JRuby looks like…

C:\Users\Jon\Documents\RubyDev\sandbox\>jruby system\_ruby.rb  
[INFO] doing some work via system()…  
jruby 1.6.0.RC1 (ruby 1.9.2 trunk 136) (2011-01-10 769f847) (Java  
HotSpot™ Client  
VM 1.6.0\_23) [Windows 7-x86-java]  
[INFO] OK, I’m back.  
[INFO] playing with processes via system()…

[1] [Process Monitor - Sysinternals | Microsoft Learn](http://technet.microsoft.com/en-us/sysinternals/bb896645)  
[2]  
[http://github.com/jonforums/measurements/blob/master/lib/tracers/processmonitor.rb](http://github.com/jonforums/measurements/blob/master/lib/tracers/processmonitor.rb)

Jon

* * *

blog: [http://jonforums.github.com/](http://jonforums.github.com/)  
twitter: @jonforums

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [February 5, 2011, 8:10am UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/2 "2011-02-05T08:10:47Z")

</div>

jruby.launch.inproc=false might help

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [February 5, 2011, 8:13am UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/3 "2011-02-05T08:13:23Z")

</div>

setting jruby.launch.inproc property to false help?

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [February 5, 2011, 4:40pm UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/4 "2011-02-05T16:40:42Z")

</div>

> setting jruby.launch.inproc property to false help?

Thanks Roger…will give it a try…forgot about that one ☹

Jon

* * *

blog: [http://jonforums.github.com/](http://jonforums.github.com/)  
twitter: @jonforums

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [February 5, 2011, 7:23pm UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/5 "2011-02-05T19:23:52Z")

</div>

> > setting jruby.launch.inproc property to false help?
> 
> Thanks Roger…will give it a try…forgot about that one ☹

Updated [figuring out MRI and JRuby's use of system() · GitHub](https://gist.github.com/811728) and run via jruby  
-Xlaunch.inproc=false system\_ruby.rb but that doesn’t fix things.

On 1.6.0.RC1 in 1.9 mode, the issue is not where I thought it was. It’s  
the first system() call with “start…” (line 23) that never returns  
(MRI’s system(“start…”) does return) as this shows:

C:\Users\Jon\Documents\RubyDev\sandbox\>jruby -Xlaunch.inproc=false  
system\_ruby.rb  
[INFO] doing some work via system()…  
jruby 1.6.0.RC1 (ruby 1.9.2 trunk 136) (2011-01-10 769f847) (Java  
HotSpot™ Cli  
VM 1.6.0\_23) [Windows 7-x86-java]  
[INFO] OK, I’m back from the working case.  
[INFO] playing with processes via system()…  
[INFO] starting 1st system

I’m checking in 1.8 mode and on 1.5.6 to see if JRuby’s  
system(“start…”) behaves differently.

Jon

* * *

blog: [http://jonforums.github.com/](http://jonforums.github.com/)  
twitter: @jonforums

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [February 6, 2011, 3:12am UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/6 "2011-02-06T03:12:09Z")

</div>

> Updated [figuring out MRI and JRuby's use of system() · GitHub](https://gist.github.com/811728) and run via jruby  
> -Xlaunch.inproc=false system\_ruby.rb but that doesn’t fix things.

I assume that’s equivalent to starting it like

-J-Djruby.launch.inproc=false  
?  
-r

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [February 10, 2011, 9:33pm UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/7 "2011-02-10T21:33:46Z")

</div>

> [INFO] OK, I’m back from the working case.  
> [INFO] playing with processes via system()…  
> [INFO] starting 1st system
> 
> I’m checking in 1.8 mode and on 1.5.6 to see if JRuby’s system(“start…”)  
> behaves differently.

Tried the above snippet [figuring out MRI and JRuby's use of system() · GitHub](https://gist.github.com/811728) with 1.6.0.RC2  
and 1.5.6 in both 1.8 and 1.9 modes…works on MRI Ruby and fails on  
JRuby as shown above.

Roger…have you tried the gist on your RC2 using the following and have  
it working?

jruby --1.9 -Xlaunch.inproc=false system\_ruby.rb  
jruby -Xlaunch.inproc=false system\_ruby.rb

Jon

* * *

blog: [http://jonforums.github.com/](http://jonforums.github.com/)  
twitter: @jonforums

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [February 11, 2011, 3:39pm UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/8 "2011-02-11T15:39:49Z")

</div>

> looks like a bug:
> 
> system(“start ruby.exe -e sleep”)
> 
> returns immediately in windows, but “waits” in jruby, for some reason.
> 
> I’d file a JIRA for it 🙂

I agree and will file a JIRA later this morning. Thanks for  
reproducing…what Windows version?

FWIW, a more relevant quick test is

jruby --1.9 -Xlaunch.inproc=false -ve “system(‘start dxdiag.exe’)”

> In the meantime, ffi might help.
> 
> [FFI wrapper for CreateProcess() · GitHub](https://gist.github.com/280865)

Interesting, thanks for the pointer as I’m a fan of FFI. However, it’s  
an unwelcome dependency for what I’m trying to do.

I’d rather have this Windows bug fixed in 1.6.0, or find a usable  
workaround.

Jon

* * *

blog: [http://jonforums.github.com/](http://jonforums.github.com/)  
twitter: @jonforums

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [February 11, 2011, 1:43am UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/9 "2011-02-11T01:43:28Z")

</div>

looks like a bug:

system(“start ruby.exe -e sleep”)

returns immediately in windows, but “waits” in jruby, for some reason.

I’d file a JIRA for it 🙂

In the meantime, ffi might help.

> <https://gist.github.com/jarib/280865>

-r

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [February 11, 2011, 4:16pm UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/10 "2011-02-11T16:16:04Z")

</div>

> Interesting, thanks for the pointer as I’m a fan of FFI. However, it’s  
> an unwelcome dependency for what I’m trying to do.
> 
> I’d rather have this Windows bug fixed in 1.6.0, or find a usable  
> workaround.

IO.popen?  
I guess ffi is bundled with jruby but not with MRI.  
-r

---

<div class="post-metadata">

**Author:** ![ratchetcat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ratchetcat](https://www.ruby-forum.com/u/ratchetcat)\
**Post date:** [February 11, 2011, 5:20pm UTC](https://www.ruby-forum.com/t/groking-system-on-windows/202747/11 "2011-02-11T17:20:44Z")

</div>

[http://jira.codehaus.org/browse/JRUBY-5493](http://jira.codehaus.org/browse/JRUBY-5493)

> IO.popen?

Next on the to-look-at list in case this can’t be resolved for 1.6.0 and  
as a workaround for 1.5.6.

Jon

* * *

blog: [http://jonforums.github.com/](http://jonforums.github.com/)  
twitter: @jonforums
