1

I want to make a button inside my GUI that triggers a shell script. How can I do this?

Thanks!

1 Answer 1

2

you need to put

def action_name
  output = `/path/to/your/shell/script`
end

into an action that can be called from the gui. the backtick operator `` makes a system call and returns the standard output of your shell script.

UPD: This is the easy way. If you have a long running shell script you should consider using something like Delayed::Job

Sign up to request clarification or add additional context in comments.

3 Comments

after that script has been invoked, can I safely use a redirect?
I can't think of anything why not, so I would say yes
The backticks collect all of the output. So if you redirect after the action it won't be called until after the shell script completes. So the redirect will be fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.