Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Input streams are closed after sending data to commands #245

Closed
dylanahsmith opened this Issue Jul 26, 2012 · 3 comments

Comments

Projects
None yet
2 participants
Contributor

dylanahsmith commented Jul 26, 2012

Problem:

Commands will appear to hang when trying to send data over standard input, because they will wait for the input stream to be closed.

Example:

role :main, 'localhost'

task :main do
  run "cat", :data => 'hello'
end

Run with cap main and notice how it hangs when executing the command.

Possible Solution:

Call ch.eof! after ch.send_data(options[:data]) in command.rb

Contributor

carsomyr commented Jul 27, 2012

Would you mind submitting a formal pull request for this and closing the issue? Is what you described the reason I have to insert an exit statement when running bash as the command? (Otherwise run hangs as you described.)

Contributor

dylanahsmith commented Jul 27, 2012

Is what you described the reason I have to insert an exit statement when running bash as the command?

Yes.

Would you mind submitting a formal pull request for this and closing the issue?

Sure, but I wanted a better solution first, since this solution is quite use case specific.

For instance, run can take a block which might want to read from standard input, which is used in Capistrano::Deploy::Strategy::Remote#scm_run. Since this block is only called when output it received, it wouldn't be able to send data before any output is received without using the :data option. So this solution would actually conflict with this use case.

A better solution would check wether a block is passed to run, if this isn't the case it would close the standard input stream.

Closing the standard input stream may be useful even if a block is passed to run. So an explicit option to change the default behaviour would account for this use case, and run could ||= this option based on whether a block is passed to the method. This would make it easier to implement, a solution because run just uses run_tree, which wouldn't know whether a block is passed to run, so an options would propagate this knowledge.

Contributor

carsomyr commented Aug 10, 2012

I'm closing this issue, as pull request #246 has been merged.

@carsomyr carsomyr closed this Aug 10, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment