| Start |
|---|
| Recommended ways to execute shell code in Ruby: Open3.popen3 or Open3.capture3: Open3.popen3 Popen3 runs in a sub-process and returns stdin, stdout, stderr and wait_thr. or will output: stdout is: stderr is:fatal: Not a git repository (or any of the parent directories): .git or will output: Pinging www.google.com [216.58.223.36] with 32 bytes of data: Open3.capture3: or Not recommended though, due to additional overhead and the potential for shell injections. If the command reads from stdin and you want to feed it some data: Run the command with a different working directory, by using chdir: |
| Clasic ways to execute shell code in Ruby: Exec: or The System Command: Will output "hello world" in the command window. or The system command can return a true if the command was successful or nill when not. The backticks (`):
You can also catch the result. IO.popen: RemarksExec: The System Command: The output of system function will always be true or nil depending on whether or not the script has been executed without error. Therefore, every error while executing the script will not be passed to our application. The main operation never needs to worry about capturing an exception raised from the child process. In this case the output is nil because the child process raised an exception. The backticks (`): IO.popen: Popen3: $? (same as $CHILD_STATUS) |
Read Article
https://develop.horje.com/learn/1434/reference