Given a sample script that opens /dev/tty
:
# sample.rb
tty=File.open("/dev/tty", "w+")
tty.print "> "
tty.puts tty.gets.upcase
I can run it with normal jruby just fine:
% jruby sample.rb
> hello
HELLO
%
However, if I try to use /dev/tty
with nailgun, then the tty is bound to the nailgun server, not the client:
# server terminal | # client terminal
% jruby --ng-server |
NGServer 0.9.1 started on all interfaces, port 2113. |
| % jruby --ng sample.rb
> hello |
HELLO |
| %
(the vertical spacing is to show timing, the actual output for each lacks the blank lines)
Is this expected behaviour, or a bug?
If it's expected behaviour, is there a way I can detect whether a script is being run with --ng
so I can
avoid opening /dev/tty
?
Looking at the Nailgun client/server protocol, it doesn't look like it supports what would need to happen to use the client's /dev/tty
(have client open a file, read/write from client to server).
Whether it's a bug or not, it's outside the capabilities of Nailgun currently.
Detecting whether we're on a Nailgun server can be done via
# true if on a nailgun server, false elsewise
system("ps -fp #{Process.pid} | grep NGServer > /dev/null")