Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing the "system" command in Java
    text
    copied!<p>I have need for a "system" function call, the same as those in Python, Perl, PHP, Ruby, &amp;c. It will be a component of a JavaScript standard library called Narwhal, when it's run on the Rhino JavaScript engine, which is in turn run on Java.</p> <p>The trouble is that Java's standard library appears to have abstracted away the ability to spawn a subprocess that shares the parent process's stdio. This means that you can't defer interactivity to the subprocess.</p> <p>My first crack at this was to implement Python's subprocess.popen. This uses three "pumper" threads to actively copy the parent process's stdio independently (to prevent deadlock). Unfortunately this is giving us two problems. First, the input does not close automatically when the sub-process voluntarily exits. Second, the streams to the child process do not buffer and flush properly.</p> <p>I'm looking for solutions that would make our require("os").system() command work as one would expect.</p> <p>The project is at <a href="http://narwhaljs.org" rel="nofollow noreferrer">http://narwhaljs.org</a></p> <p>Relevant code:</p> <ul> <li><a href="http://github.com/tlrobinson/narwhal/blob/d147c160f11fdfb7f3c0763acf352b2b0e2713f7/lib/os.js#L10" rel="nofollow noreferrer">http://github.com/tlrobinson/narwhal/blob/d147c160f11fdfb7f3c0763acf352b2b0e2713f7/lib/os.js#L10</a></li> <li><a href="http://github.com/tlrobinson/narwhal/blob/d147c160f11fdfb7f3c0763acf352b2b0e2713f7/engines/rhino/lib/os-engine.js#L37" rel="nofollow noreferrer">http://github.com/tlrobinson/narwhal/blob/d147c160f11fdfb7f3c0763acf352b2b0e2713f7/engines/rhino/lib/os-engine.js#L37</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload