Project

General

Profile

Actions

Bug #18811

closed

PTY I/O not working on AIX 7.x

Added by hspem (Per-Erik Martin) over 2 years ago. Updated over 2 years ago.

Status:
Feedback
Target version:
-
ruby -v:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [powerpc-aix7.1.0]
[ruby-core:108737]

Description

The attached test script simply executes a command under a PTY and captures the output and exit code.
This works on Linux (all supported versions of Redhat, Debian, Ubuntu, and SuSE) as well as Solaris 11.4 on sparc and x86.
But on AIX 7.1 - 7.3, it doesn't. This was tested with a ruby 3.1.2 that I built, but it exhibits the same behavior on other ruby versions as well, like 2.7.5 from IBM's freeware repo.

The core of the attached program is:

begin
  PTY.spawn($command) do |r, w, pid|
    w.close
    begin
      r.each do |line|
        puts "Got line \"#{line.chomp}\""
      end
    rescue Errno::EIO
      # ignore
    rescue => e
      $stderr.puts "Read error: #{e}"
    ensure
      Process.wait pid
    end
    $exit_status = $?.exitstatus
  end
rescue => e
  $stderr.puts "PTY.spawn error: #{e}"
end

This should read the output from echo but doesn't:

# ./ptytest.rb 'echo b'
Exit status 0
# 

It does execute the command, but it seems it can't read the output:

# ./ptytest.rb 'exit 3'
Exit status 3
# cat /tmp/e.txt
cat: 0652-050 Cannot open /tmp/e.txt.
# ./ptytest.rb 'echo b > /tmp/e.txt'
Exit status 0
# cat /tmp/e.txt
b
# 

However, the unit tests for PTY work, so how it this possible? It turns out that all the unit tests run ruby (tinyruby really), and this works:

# ./ptytest.rb 'ruby -e "puts \"b\""'
Got line "b"
Exit status 0
# 

as well as this:

# ./ptytest.rb 'ruby -e "system \"echo b\""'
Got line "b"
Exit status 0
# 

So I'm at a loss here. How come it works to use "ruby" but no other commands? Is there something wrong with the script? If so, why does it work on all other platforms?


Files

ptytest.rb (534 Bytes) ptytest.rb hspem (Per-Erik Martin), 05/30/2022 07:26 AM
pty.c.patch (655 Bytes) pty.c.patch hspem (Per-Erik Martin), 06/07/2022 07:15 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0