1

I am designing a ruby program that needs to run a command and store it a variable.

    var = exec('some command');

This doesn't work the way I want it to, it just prints the output from the command prompt and then ends the program. So is there a function that doesn't end the program, doesn't print the cmd output and stores the information in a variable?

Thanks in advance.

2 Answers 2

4

You need to use either Ruby's built in backtick syntax, or use %x

output = `some command`

or

output = %x(some "command")
Sign up to request clarification or add additional context in comments.

Comments

0

Open3 grants you access to stdin, stdout, stderr and a thread to wait the child process when running another program. You can specify various attributes, redirections, current directory, etc., of the program as Process.spawn.

See the various ways of executing a command

1 Comment

Open3 has a lot of capability, but wading through the documentation would stifle the OPs creativity. Using capture2, capture2e or capture3 would be good starting places if not using backticks or %x are not friendly enough.

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.