0

This is my recipe.rb:

require 'mixlib/shellout'
require "pry"

find = Mixlib::ShellOut.new("echo hostname -I")
find.run_command.stdout

What should I write it in my spec?

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
  • What do you want the spec to test? That a certain command has been executed? That a certain thing has been printed to STDOUT? Btw, I'm not sure this is doing what you expect... It's literally printing the string `"hostname -I"`; it's not actually running the `hostname` command. I don't think you mean to write `echo` there. – Tom Lord Aug 16 '21 at 11:33
  • I want to run this command and display stdout –  Aug 17 '21 at 07:34

1 Answers1

0

You don't need the echo command to get the output. you can directly run the command through mixlib/shellout and get then get the command output from stdout.

require 'mixlib/shellout'

find = Mixlib::ShellOut.new("hostname -I")
find.run_command.stdout
Chandan
  • 11,465
  • 1
  • 6
  • 25