Skip to content

input doesn't get through and stdout is line buffered #31

Open
@x-yuri

Description

@x-yuri

Put the following file on a server:

1.sh:

#!/usr/bin/env bash
read -p 'Enter your name: ' name
echo Hello, $name
$ ssh user@domain -t ./1.sh
Enter your name: name
Hello, name
Connection to domain closed.
$ ruby -e "exec('ssh user@domain -t ./1.sh')"
Enter your name: name
Hello, name
Connection to domain closed.

1.rb:

script = ["ssh", "user@domain", "-tt", './1.sh']
status = Open4.popen4(*script) do |pid, _stdin, stdout, stderr|
  trap('INT') { Process.kill 'KILL', pid }
  stdout_thread = Thread.new do
    while (line = stdout.gets)
      puts "stdout: '#{line}'"
    end
  end
  stdout_thread.join
end
$ ./1.sh
^Cstdout: 'Enter your name: '

This gem is used by mina to, say, execute scripts remotely. And if any command asks for user input, the prompt is never shown. It's not even clear what's going on, it just hangs until interrupted. Is there a way to work around it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions