From: "hspem (Per-Erik Martin)" Date: 2022-05-30T11:55:46+00:00 Subject: [ruby-core:108739] [Ruby master Bug#18811] PTY I/O not working on AIX 7.x Issue #18811 has been updated by hspem (Per-Erik Martin). I had some instances with inconsistent behavior and got an idea... ``` shell # ./ptytest.rb 'echo foo' Exit status 0 # ./ptytest.rb 'echo foo' Exit status 0 # ./ptytest.rb 'echo foo' Exit status 0 # ./ptytest.rb 'sleep 1;echo foo' Got line "foo" Exit status 0 # ./ptytest.rb 'sleep 1;echo foo' Got line "foo" Exit status 0 # ./ptytest.rb 'sleep 1;echo foo' Got line "foo" Exit status 0 # ``` So it's some kind of race condition apparently. If the command takes some time before it generates the output, it works. The systems I'm testing on are notoriously slow (virtual machines on not very new hardware). This might explain why this has gone unnoticed by others, if you have fast enough systems and/or run commands that don't print output too soon, it will appear to work. ---------------------------------------- Bug #18811: PTY I/O not working on AIX 7.x https://bugs.ruby-lang.org/issues/18811#change-97794 * Author: hspem (Per-Erik Martin) * Status: Feedback * Priority: Normal * Assignee: kanemoto (Yutaka Kanemoto) * ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [powerpc-aix7.1.0] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- 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: ``` ruby 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: ``` shell # ./ptytest.rb 'echo b' Exit status 0 # ``` It does execute the command, but it seems it can't read the output: ``` shell # ./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: ``` shell # ./ptytest.rb 'ruby -e "puts \"b\""' Got line "b" Exit status 0 # ``` as well as this: ``` shell # ./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) -- https://bugs.ruby-lang.org/ Unsubscribe: