Reputation: 795
I need to know how to send terminal commands through Ruby to execute another application. I would like to call the SIKULI script at a certain point within my Watir script to handle some steps that Watir can't.
I am not sure how to do it. I read a few of the articles here at Stack Overflow, but can't get it to work.
These are the steps to execute it manually:
jfleck-mbp:~ joe.fleck$ SIKULI_HOME=/Applications/Sikuli-IDE.app/Contents/Resources/Java
jfleck-mbp:~ joe.fleck$ java -jar $SIKULI_HOME/sikuli-script.jar '/Users/joe.fleck/Desktop/Save_File_Button.sikuli'
These are in a Ruby file I am trying to execute:
require 'rubygems'
system('SIKULI_HOME=/Applications/Sikuli-IDE.app/Contents/Resources/Java')
system ("java -jar $SIKULI_HOME/sikuli-script.jar '/Users/joe.fleck/Desktop/Save_File_Button.sikuli'")
The output I get is:
Unable to access jarfile /sikuli-script.jar
which tells me the first line in my script did not execute which allows the access.
Any suggestions would be appreciated.
Upvotes: 1
Views: 403
Reputation: 3120
Fix it like this:
ENV['SIKULI_HOME'] = '/Applications/Sikuli-IDE.app/Contents/Resources/Java'
system ("java -jar $SIKULI_HOME/sikuli-script.jar '/Users/joe.fleck/Desktop/Save_File_Button.sikuli'")
The issue is that when you call system
, you are invoking a child process. Child processes inherit the environment from the parent processes (in this case your Ruby script). Using system
to set an environment variable sets it for that child process only, the next call to system is a new child process with a fresh environment.
The solution shown above sets the environment variable in the parent process, thus it will be set for all child processes.
Upvotes: 1
Reputation: 3143
I think you're getting a different shell with each system()
command.
One easy way to verify, and a more maintainable approach, IMHO, would be put all the commands in a single (bash/zsh/whatever) script and run that with system()
.
Upvotes: 3