From 0d60d2d0471620d05c8217335506ed314a3dd2d4 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Tue, 19 Mar 2024 09:54:56 -0400 Subject: [PATCH] made run return the standard out output --- lib/sftp/shell.rb | 9 +++++---- spec/sftp_spec.rb | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/sftp/shell.rb b/lib/sftp/shell.rb index da1ddde..7183214 100644 --- a/lib/sftp/shell.rb +++ b/lib/sftp/shell.rb @@ -2,10 +2,11 @@ module SFTP module Shell def self.run(array_of_commands) command_str = [array_of_commands].join(" ") - `bash -c \"#{command_str}\"` - return if $CHILD_STATUS.success? - - raise Error, "Error occurred during SFTP process: #{$CHILD_STATUS.exitstatus}" + output = `bash -c \"#{command_str}\"` + unless $CHILD_STATUS.success? + raise Error, "Error occurred during SFTP process: #{$CHILD_STATUS.exitstatus}" + end + output end end end diff --git a/spec/sftp_spec.rb b/spec/sftp_spec.rb index 6c04fe9..bfa1843 100644 --- a/spec/sftp_spec.rb +++ b/spec/sftp_spec.rb @@ -105,5 +105,9 @@ it "throws Error when run fails" do expect { @shell.run ["gobbledegook"] }.to raise_error(SFTP::Error) end + + it "returns the output from the command" do + expect(@shell.run(["ls"]).class.to_s).to eq("String") + end end end