jarib/childprocess — Issue #18: Detecting a failure to execute the process 
Author: mitchellh
Created: 2011-12-19 02:00:14+00:00
State: open

ChildProcess currently doesn't provide a uniform way to detect that there was a failure to execute the given process. Java differs from Linux which differs from Windows.

It would be nice if there was a uniform error I could catch that would signal that ChildProcess wasn't able to start the childprocess... though I'm not sure how to do that easily portably.

In the mean time, I'm building it in to a helper to catch the various exit cases...

For example, executing `foo bar baz`...

## On Linux

The following comes through via the `stderr` of the child process:

```
/Users/mitchellh/.rvm/gems/ruby-1.9.3-p0/gems/childprocess-0.2.3/lib/childprocess/unix/process.rb:94:in `exec': No such file or directory - foo (Errno::ENOENT)
from /Users/mitchellh/.rvm/gems/ruby-1.9.3-p0/gems/childprocess-0.2.3/lib/childprocess/unix/process.rb:94:in `block in launch_process'
from /Users/mitchellh/.rvm/gems/ruby-1.9.3-p0/gems/childprocess-0.2.3/lib/childprocess/unix/process.rb:83:in `fork'
from /Users/mitchellh/.rvm/gems/ruby-1.9.3-p0/gems/childprocess-0.2.3/lib/childprocess/unix/process.rb:83:in `launch_process'
from /Users/mitchellh/.rvm/gems/ruby-1.9.3-p0/gems/childprocess-0.2.3/lib/childprocess/abstract_process.rb:58:in `start'
from /Users/mitchellh/code/personal/ruby/vagrant/lib/vagrant/util/subprocess.rb:37:in `execute'
from /Users/mitchellh/code/personal/ruby/vagrant/lib/vagrant/util/subprocess.rb:15:in `execute'
from test.rb:7:in `

'
```

## On Java

The following exception is raised directly in the parent process:

```
NativeException: java.io.IOException: Cannot run program "foo" (in directory "/Users/mitchellh/code/personal/ruby/vagrant"): error=2, No such file or directory
launch_process at /Users/mitchellh/.rvm/gems/jruby-1.6.5/gems/childprocess-0.2.3/lib/childprocess/jruby/process.rb:59
start at /Users/mitchellh/.rvm/gems/jruby-1.6.5/gems/childprocess-0.2.3/lib/childprocess/abstract_process.rb:58
execute at /Users/mitchellh/code/personal/ruby/vagrant/lib/vagrant/util/subprocess.rb:37
execute at /Users/mitchellh/code/personal/ruby/vagrant/lib/vagrant/util/subprocess.rb:15
(root) at test.rb:7
```

## On Windows

(I haven't tested on Windows, sorry, but I imagine it will be different)