I have an application that runs continuously, downloading output from the server and sending strings to stdout. I want to process this output with a Ruby script. The \n-terminated lines .
For example, I try to run this on the command line:
myapp.exe | my_script.rb
... s my_script.rbis defined as:
while $stdin.gets
puts $_
end
Ultimately, I will process strings using regular expressions and display some summary data, but for now, I'm just trying to hook in some basic functions. When I run above, I get the following error:
my_script.rb:1:in `gets': Bad file descriptor (Errno::EBADF)
from my_script.rb:1
I am running this on Windows Server 2003 R2 SP2 and Ruby 1.8.6.
How can I continuously process stdin in a Ruby script? (Continuously, as in not processing the file, but it works until I kill it.)
EDIT:
, . . -, , Ruby stdin Windows 2003R2. , , , script popen myapp.exe fork ed. , fork Windows, .
, POpen4, RubyGem, popen Windows. , script, , , myapp.exe:
file: my_script.rb
require 'rubygems'
require 'popen4'
status =
POpen4::popen4("myapp.exe") do |stdout, stderr, stdin, pid|
puts pid
while s = stdout.gets
puts s
end
end
script myapp.exe, , .