S
Stephan Wehner
So I wrote a little Ruby script using pipes roughly like this
-- BEGIN SCRIPT ----
#!/usr/bin/ruby -n
def process(line)
f = IO.popen('some_executable', 'w')
f.puts <<END_INPUT
some executable commands
#{line}
some executable commands
END_INPUT
f.close
puts
puts line
end
process $_ unless $_ =~ /#/
-- END SCRIPT -----
Now this works nicely, I invoke it with
./script input_file > result
the "some_executable" prints to STDOUT results as I expect (given the
lines from input_file) and I can read the results in the "result" file
However, the output of the puts / puts line at the end of
the process method does not occur at the places I expect.
The output of "some_executable" for several "lines" shows up on STDOUT,
then the output of the puts / puts line for several "lines" shows up on
STDOUT, whereas they should simply alternate (depending on the "line"
value).
Am I missing something about pipes, and how the input/output streams are
hooked up?
I am guessing that a calling STDOUT.flush before and after the puts/puts
line statements will repair this, but I'm wondering why this would be
necessary.
This is with ruby 1.8.4 (2005-12-24) [i386-linux]
Thanks
Stephan
-- BEGIN SCRIPT ----
#!/usr/bin/ruby -n
def process(line)
f = IO.popen('some_executable', 'w')
f.puts <<END_INPUT
some executable commands
#{line}
some executable commands
END_INPUT
f.close
puts
puts line
end
process $_ unless $_ =~ /#/
-- END SCRIPT -----
Now this works nicely, I invoke it with
./script input_file > result
the "some_executable" prints to STDOUT results as I expect (given the
lines from input_file) and I can read the results in the "result" file
However, the output of the puts / puts line at the end of
the process method does not occur at the places I expect.
The output of "some_executable" for several "lines" shows up on STDOUT,
then the output of the puts / puts line for several "lines" shows up on
STDOUT, whereas they should simply alternate (depending on the "line"
value).
Am I missing something about pipes, and how the input/output streams are
hooked up?
I am guessing that a calling STDOUT.flush before and after the puts/puts
line statements will repair this, but I'm wondering why this would be
necessary.
This is with ruby 1.8.4 (2005-12-24) [i386-linux]
Thanks
Stephan