Решение
class Terminal
def self.runInNewWindow(command)
`osascript -e 'tell app "Terminal"
do script "#{command}"
end tell'`
end
end
class File
def self.create(filename, text)
fo = File.open(filename, "w+")
File.chmod(0777, filename)
fo.puts text
fo.close
end
end
Использование
filename = "file"
#closeWindowCommand = "osascript -e 'tell app \"Terminal\" to close first window' & exit"
removeFileCommand = "rm #{filename}"
command = "#{RUBY_VERSION}"
path = File.expand_path('../', __FILE__)
File.create(filename, "echo #{command}; #{removeFileCommand}")
Terminal.runInNewWindow("cd #{path}; ./#{filename}")
Полный образец
файл "run.rb"
class Terminal
def self.runInNewWindow(command)
`osascript -e 'tell app "Terminal"
do script "#{command}"
end tell'`
end
end
class File
def self.create(filename, text)
fo = File.open(filename, "w+")
File.chmod(0777, filename)
fo.puts text
fo.close
end
end
filename = "file"
#closeWindowCommand = "osascript -e 'tell app \"Terminal\" to close first window' & exit"
removeFileCommand = "rm #{filename}"
command = "#{RUBY_VERSION}"
path = File.expand_path('../', __FILE__)
File.create(filename, "echo #{command}; #{removeFileCommand}")
Terminal.runInNewWindow("cd #{path}; ./#{filename}")
файл "run"
cd "$(dirname "$0")"
ruby run.rb
Выполнить пример
Открыть файл run
Результаты
