There are many ways in ruby to make a system call.
I'm currently using open3 in a method like this:
def run_system_command { |system_command|
stdout_str = ""
stderr_str = ""
status = ""
Open3.popen3(system_command) do |stdin, stdout, stderr, wait_thr|
stdin.close
stdout_str = stdout.read # read stdout to string. note that this will block until the command is done!
stderr_str = stderr.read # read stderr to string
status = wait_thr.value # will block until the command finishes; returns status that responds to .success? etc
end
return stdout_str, stderr_str, status
}
It works fine when running basic system commands like tar
or ls
or cd
etc...
But when I try to run a program like ios-deploy
from an Automator 'Run Shell Script', I don't get any results:
(Assume the run_system_command method is defined in the block. Automator text fields don't expand so I couldn't show you the whole thing)
I get no output from such a call, which makes me think that making a system call in Ruby doesn't see the ios-deploy
program.
Note that I've made sure that I can get output from Ruby in general by using 'Set Value of Variable' and 'Display Notification' actions in a simple "Hello World" 'Run Shell Script' action.
How can I tell ruby how to use / where to find the program?
Some kind of path adjustment? I'm not sure where to make such a change when calling Ruby in this way.
Update: I'm able to get the command to work by using the full path to the program:
/usr/local/bin/ios-deploy
Is there a way to tell Ruby/Automator where to find that program without having to explicitly use the path prefix every time?