Skip to content

Commit

Permalink
made run return the standard out output
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Mar 19, 2024
1 parent 4ff7df7 commit 0d60d2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/sftp/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions spec/sftp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0d60d2d

Please sign in to comment.