diff --git a/CHANGELOG.md b/CHANGELOG.md index e9808bca5..5b06d34cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ - "--no-provision" once again works for certain commands. [GH-591] - Resuming a VM from a saved state will show an error message if there would be port collisions. [GH-602] + - `vagrant ssh -c` will now exit with the same exit code as the command + run. [GH-598] ## 0.8.10 (December 10, 2011) diff --git a/lib/vagrant/command/ssh.rb b/lib/vagrant/command/ssh.rb index e21166ecd..77b2deed4 100644 --- a/lib/vagrant/command/ssh.rb +++ b/lib/vagrant/command/ssh.rb @@ -40,16 +40,23 @@ module Vagrant protected def ssh_execute(vm, command=nil) + exit_status = 0 + @logger.debug("Executing command: #{command}") vm.ssh.execute do |ssh| ssh.exec!(command) do |channel, type, data| - if type != :exit_status + if type == :exit_status + exit_status = data.to_i + else # Print the SSH output as it comes in, but don't prefix it and don't # force a new line so that the output is properly preserved vm.ui.info(data.to_s, :prefix => false, :new_line => false) end end end + + # Exit with the exit status we got from executing the command + exit exit_status end def ssh_connect(vm) diff --git a/test/acceptance/ssh_test.rb b/test/acceptance/ssh_test.rb index 5be5ba85f..698c79efc 100644 --- a/test/acceptance/ssh_test.rb +++ b/test/acceptance/ssh_test.rb @@ -32,8 +32,13 @@ describe "vagrant ssh" do assert_execute("vagrant", "init") assert_execute("vagrant", "up") - result = assert_execute("vagrant", "ssh", "-c", "echo foo") + result = execute("vagrant", "ssh", "-c", "echo foo") + result.exit_code.should == 0 result.stdout.should == "foo\n" + + result = execute("vagrant", "ssh", "-c", "foooooooooo") + result.exit_code.should == 127 + #result.stderr.should =~ /foooooooooo: command not found/ end # TODO: