{"action":"closed","issue":{"url":"https://api.github.com/repos/bastienleonard/hutte/issues/2","labels_url":"https://api.github.com/repos/bastienleonard/hutte/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/bastienleonard/hutte/issues/2/comments","events_url":"https://api.github.com/repos/bastienleonard/hutte/issues/2/events","html_url":"https://github.com/bastienleonard/hutte/issues/2","id":102496110,"number":2,"title":"Support command output capture","user":{"login":"bastienleonard","id":705274,"avatar_url":"https://avatars.githubusercontent.com/u/705274?v=3","gravatar_id":"","url":"https://api.github.com/users/bastienleonard","html_url":"https://github.com/bastienleonard","followers_url":"https://api.github.com/users/bastienleonard/followers","following_url":"https://api.github.com/users/bastienleonard/following{/other_user}","gists_url":"https://api.github.com/users/bastienleonard/gists{/gist_id}","starred_url":"https://api.github.com/users/bastienleonard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bastienleonard/subscriptions","organizations_url":"https://api.github.com/users/bastienleonard/orgs","repos_url":"https://api.github.com/users/bastienleonard/repos","events_url":"https://api.github.com/users/bastienleonard/events{/privacy}","received_events_url":"https://api.github.com/users/bastienleonard/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-08-22T02:10:05Z","updated_at":"2015-08-22T17:39:02Z","closed_at":"2015-08-22T17:39:02Z","body":"Continued from issue #1:\r\n\r\n>now to figure out how to get the output of \"run\" commands into variables for processing.\r\nthanks.\r\n\r\nThere isn't a public API for that, but I'll try to add it soon.\r\nIn the mean time, if you really need to capture the output of a command, you can use the internal API.\r\nThis will be a bit more complicated than necessary because the internal API uses callbacks, so that the output of long-running commands in shown in real time.\r\n\r\nFor remote commands (`self` is a [Dsl](https://bastienleonard.github.io/hutte/reference/dsl.html) instance, if the block you passed to SshSession.run() takes a parameter, then pass it instead):\r\n\r\n```ruby\r\nHutte::ssh_exec(self.instance_variable_get('@session'), 'pwd') do |callback|\r\n  callback.on_stdout do |data|\r\n    puts data\r\n  end.on_stderr do |data|\r\n    puts data\r\n  end.on_exit_status_received do |status|\r\n    puts \"Exit status: #{status}\"\r\n  end\r\nend\r\n```\r\n\r\nFor local commands:\r\n\r\n```ruby\r\nstatus = Hutte::LocalShell.run('pwd') do |callback|\r\n  callback.on_stdout do |data|\r\n    puts data\r\n  end.on_stderr do |data|\r\n    puts data\r\n  end\r\nend\r\n\r\nputs \"Exit status: #{status}\"\r\n```\r\n\r\nNote that you're  on your own here, for example Hutte won't raise an error if the command fails (status != 0). Also error checking is minimal, your app will crash if a callback that wasn't supplied gets called."}}