Shellout question in library


#1

I am writing a library to do a few thigns - one is to determine if a mount exists.

Very simple but brain is not working today:

 def has_mount?
      mount_point = 'ephemeral0'
      shell_out!("grep -qs #{mount_point} /proc/mounts", {:returns => [0,2]})
  end

When it returns 1, I get this not what I want to just proceed with the rest of my code:

[2015-12-18T16:29:45+00:00] ERROR: Expected process to exit with [0, 2], but received '1'

Thanks for any guidance!
Jenn


#2

The ! version raises an exception on failure, you want to use shell_out without the ! which always returns the command object even for errors.

shell_out("grep -qs #{mount_point} /proc/mounts", returns: [0,2]).error?