Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: JRuby 1.7.0.pre2
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Noticing that Rake always truncate my output for `rake -T` at 80 chars (which is quite annoying), I wondered what was not working.

      Rake uses `stty size` and `tput cols` to guess the terminal width.
      The first gives "stty: stdin isn't a terminal" and the second returns 80, which is not my terminal width (176).

      So, what is the recommended way to obtain the terminal width in JRuby?

      (Adding export RAKE_COLUMNS=$COLUMNS in my .zshrc works but that's just a workaround for rake)

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        This is another stty case where we need to do subprocess launching separate from Java's normal launching, so it can inherit tty.

        I may see if I can't build out a few of the key subprocess launching APIs to use the newer Java 7 process launching that allows inheriting.

        Show
        Charles Oliver Nutter added a comment - This is another stty case where we need to do subprocess launching separate from Java's normal launching, so it can inherit tty. I may see if I can't build out a few of the key subprocess launching APIs to use the newer Java 7 process launching that allows inheriting.
        Hide
        Charles Oliver Nutter added a comment -

        Here's a monkey-patch for Kernel#` that makes it use Java 7 subprocess API with tty inheriting:

        system ~/projects/jruby $ jruby -rjruby/kernel/jruby/process_manager -e 'puts `stty`'
        speed 9600 baud;
        lflags: echoe echoke echoctl pendin
        oflags: -oxtabs
        cflags: cs8 -parenb
        
        system ~/projects/jruby $ jruby -rjruby/kernel/jruby/process_manager -e 'puts `stty size`'
        55 183
        
        system ~/projects/jruby $ jruby -rjruby/kernel/jruby/process_manager -e 'puts `tput cols`'
        80
        
        system ~/projects/jruby $ git diff
        diff --git a/src/jruby/kernel/jruby/process_manager.rb b/src/jruby/kernel/jruby/process_manager.rb
        index e69de29..47da5c7 100644
        --- a/src/jruby/kernel/jruby/process_manager.rb
        +++ b/src/jruby/kernel/jruby/process_manager.rb
        @@ -0,0 +1,27 @@
        +require 'java'
        +require 'jruby'
        +
        +module JRuby
        +  module ProcessManager
        +    java_import java.lang.ProcessBuilder
        +    Redirect = ProcessBuilder::Redirect
        +
        +    def self.`(command)
        +      pb = ProcessBuilder.new(command.split(/\W/).to_java(:string))
        +      pb.redirect_input(Redirect::INHERIT)
        +      process = pb.start
        +
        +      out = process.input_stream
        +      result = out.to_io.read
        +
        +      result
        +    end
        +  end
        +end
        +
        +module Kernel
        +  module_function
        +  def `(command)
        +    JRuby::ProcessManager.`(command)
        +  end
        +end
        \ No newline at end of file
        

        Note that `stty size` works, but `tput cols` still shows 80. Not sure what else we need to do to make that match MRI.

        I am looking into the feasibility of getting this into pre2 as a Java 7-specific impl of ` (and other process-launching stuff).

        Show
        Charles Oliver Nutter added a comment - Here's a monkey-patch for Kernel#` that makes it use Java 7 subprocess API with tty inheriting: system ~/projects/jruby $ jruby -rjruby/kernel/jruby/process_manager -e 'puts `stty`' speed 9600 baud; lflags: echoe echoke echoctl pendin oflags: -oxtabs cflags: cs8 -parenb system ~/projects/jruby $ jruby -rjruby/kernel/jruby/process_manager -e 'puts `stty size`' 55 183 system ~/projects/jruby $ jruby -rjruby/kernel/jruby/process_manager -e 'puts `tput cols`' 80 system ~/projects/jruby $ git diff diff --git a/src/jruby/kernel/jruby/process_manager.rb b/src/jruby/kernel/jruby/process_manager.rb index e69de29..47da5c7 100644 --- a/src/jruby/kernel/jruby/process_manager.rb +++ b/src/jruby/kernel/jruby/process_manager.rb @@ -0,0 +1,27 @@ +require 'java' +require 'jruby' + +module JRuby + module ProcessManager + java_import java.lang.ProcessBuilder + Redirect = ProcessBuilder::Redirect + + def self.`(command) + pb = ProcessBuilder.new(command.split(/\W/).to_java(:string)) + pb.redirect_input(Redirect::INHERIT) + process = pb.start + + out = process.input_stream + result = out.to_io.read + + result + end + end +end + +module Kernel + module_function + def `(command) + JRuby::ProcessManager.`(command) + end +end \ No newline at end of file Note that `stty size` works, but `tput cols` still shows 80. Not sure what else we need to do to make that match MRI. I am looking into the feasibility of getting this into pre2 as a Java 7-specific impl of ` (and other process-launching stuff).
        Hide
        Benoit Daloze added a comment -

        Sounds great! I will try that tomorrow.

        Show
        Benoit Daloze added a comment - Sounds great! I will try that tomorrow.
        Hide
        Benoit Daloze added a comment -

        Worked at me after a full rebuild.
        The issue with tput is weird. I guess it takes the information in a different way.

        Could this be included by default for when running with Java 7 for standard process spawning ?
        Any step towards better terminal handling is definitely good.

        Show
        Benoit Daloze added a comment - Worked at me after a full rebuild. The issue with tput is weird. I guess it takes the information in a different way. Could this be included by default for when running with Java 7 for standard process spawning ? Any step towards better terminal handling is definitely good.
        Hide
        Charles Oliver Nutter added a comment -

        I am working on a patch to add it by default, along with setting up the framework for implementing more process methods this way.

        Show
        Charles Oliver Nutter added a comment - I am working on a patch to add it by default, along with setting up the framework for implementing more process methods this way.
        Hide
        Charles Oliver Nutter added a comment - - edited

        This fix only resolves the issues on Java 7. For Java 6 and earlier we'd need to implement native process launching using jnr-posix.

        commit c7c7c7d12f43f56e5e004f8535e42118c04969f0
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Wed Jun 13 19:38:13 2012 -0500
        
            Add reimpl of Kernel#` using Java 7 process APIs.
        
        Show
        Charles Oliver Nutter added a comment - - edited This fix only resolves the issues on Java 7. For Java 6 and earlier we'd need to implement native process launching using jnr-posix. commit c7c7c7d12f43f56e5e004f8535e42118c04969f0 Author: Charles Oliver Nutter <headius@headius.com> Date: Wed Jun 13 19:38:13 2012 -0500 Add reimpl of Kernel#` using Java 7 process APIs.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Benoit Daloze
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: