I am not sure if this makes sense but I am thinking if there is a way to suppress the output shown for a command when run using the system method in ruby? I mean it should just output true or false to STDOUT and not the output of the command. What I think is it can just only be done if the command can run silently and not from the system method. Can someone provide a bit more insight?
I am not sure if this makes sense but I am thinking if there
Share
After a call to
systemthe exit code is in the special variable$?so ifuseraddreturns different values to indicate if the user was successfully added (e.g. 0 for success) then you can do the following:where the redirect to
/dev/nullwill suppress the output.Alternatively if the program being called does not use its exit code to indicate success or failure you can use backticks and search for a particular substring in the output e.g.