headius / spoon

A fork/exec replacement for FFI-capable implementations
Apache License 2.0
48 stars 12 forks source link

Can't use spoon to call Mac OS `open` or `osascript` #1

Closed matschaffer closed 12 years ago

matschaffer commented 14 years ago

I'm guessing it has something to do with these commands being mac-specific, but I thought I should bring it up since we tripped over it working on redcar.

Here's a sample script that illustrates the issue on rev 560066:

require 'rubygems'
require 'spoon'

open_command = ['open', '-a', 'Finder', '/Applications']
osa_command  = ['osascript', '-e', 'tell application "Terminal" to activate']

method = :spoon

if method == :spoon
  puts "Using spoon"
  Spoon.spawn(*open_command)
  Spoon.spawn(*osa_command)
else
  puts "Using system"
  system(*open_command)
  system(*osa_command)
end
evilrich commented 12 years ago

You should specify the path to open or use spawnp.

Spoon.spawn('/usr/bin/open', '-a', 'Finder', '/Applications')
Spoon.spawnp('open', '-a', 'Finder', '/Applications')

I suspect that part of the reason you are having a problem is that Spoon doesn't handle error codes returned by _posixspawn so you can't easily tell when it fails. I have a fix for this here: 9baec25d165bbb5568f378c62984c27a5d44bc6a

headius commented 12 years ago

The errno fix was incorporated some time ago, and the remainder of this issue is just misuse.