There are multiple ways to run system commands from Ruby.
system, using backticks (‵), using
exec, or the more advanced option of using
Open3. All of them behave in different ways.
The system method calls a system program. You have to provide the command as a string argument to this method. For example:
Sat 4/10/2021 9:11:38
Note: In Windows, the
date command also takes the input to change the system date after displaying the current system date. Press
Enter to continue
The invoked program will use the current
STDERR objects of your Ruby program. In fact, the actual return value is either
nil. In the example the date was printed through the IO object of
STDIN. The method will return true if the process exited with a zero status, false if the process exited with a non-zero status and nil if the execution failed.