J
jqwoods
I would like to create a method which executes a given shell command
and returns an array containing three things: 1) stdout of the command
as a string, 2) stderr of the command as a string, and 3) the exit
status. I'm having trouble figuring out how to get stdout and stderr
as separate output.
Here's an illustration of the desired result I'm after:
irb> my_exec_command("ls existant_file")
=> ["existant_file\n", "", 0]
irb> my_exec_command("ls NON_existant_file")
=> ["", "ls: NON_existant_file: No such file or directory\n", 2]
Any pointers on how to implement my_exec_command?
and returns an array containing three things: 1) stdout of the command
as a string, 2) stderr of the command as a string, and 3) the exit
status. I'm having trouble figuring out how to get stdout and stderr
as separate output.
Here's an illustration of the desired result I'm after:
irb> my_exec_command("ls existant_file")
=> ["existant_file\n", "", 0]
irb> my_exec_command("ls NON_existant_file")
=> ["", "ls: NON_existant_file: No such file or directory\n", 2]
Any pointers on how to implement my_exec_command?