if defined? JRUBY_VERSION
puts "JRuby #{JRUBY_VERSION}, Java #{java.lang.System.getProperty('java.version')}"
else
puts "CRuby #{RUBY_VERSION}"
end
read, write = IO.pipe
flags = write.fcntl(Fcntl::F_GETFL)
# set nonblocking flag so that ruby knows about it
write.fcntl(Fcntl::F_SETFL, flags | (Fcntl::O_NONBLOCK)) # actually clears
# clear nonblocking flag
write.fcntl(Fcntl::F_SETFL, flags & (~Fcntl::O_NONBLOCK)) # set nonblock flag
captureRuby.rb
---
require 'open3'
require 'fcntl'
if defined? JRUBY_VERSION lang.System. getProperty( 'java.version' )}"
puts "JRuby #{JRUBY_VERSION}, Java #{java.
else
puts "CRuby #{RUBY_VERSION}"
end
read, write = IO.pipe Fcntl:: F_GETFL) Fcntl:: F_SETFL, flags | (Fcntl: :O_NONBLOCK) ) # actually clears Fcntl:: F_SETFL, flags & (~Fcntl: :O_NONBLOCK) ) # set nonblock flag
flags = write.fcntl(
# set nonblocking flag so that ruby knows about it
write.fcntl(
# clear nonblocking flag
write.fcntl(
pid = spawn(" ./printFlags. py", :out => write)
write.close
puts "Manual spawn: #{read.read}"
Process.wait pid
---
printFlags.py
------
#!/usr/bin/env python3
import fcntl
import os
import sys
def decode_ flags(flags) :
"O_NONBLOCK" : os.O_NONBLOCK,
flags_to_check = {
"O_RDONLY": os.O_RDONLY,
"O_WRONLY": os.O_WRONLY,
"O_RDWR": os.O_RDWR,
"O_APPEND": os.O_APPEND,
}
result = [] check.items( ):
result. append( name)
for name, flag in flags_to_
if flags & flag:
flags &= ~flag
if flags:
result. append( str(flags) )
return "+".join(result)
stdout_io_flags = fcntl.fcntl( sys.stdout. fileno( ), fcntl.F_GETFL) flags(stdout_ io_flags) }")
print(f"stdout io flags: {stdout_io_flags} == {decode_
----
$jruby capturePython.rb
JRuby 9.4.5.0, Java 21.0.2
Manual spawn: stdout io flags: 1 == O_WRONLY
The output shows that the flag was successfully cleared.