Bug #18811
closedPTY I/O not working on AIX 7.x
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