W dniu 07.10.2010 21:21, Jeremy Bopp pisze:
> On 10/7/2010 2:07 PM, Jeremy Bopp wrote:
>> On 10/7/2010 1:40 PM, felix.leg wrote:
>>> Hi,
>>>
>>> I want to use Ruby with latex,so I wrote a simple program which waits
>>> for "\typein" command called from pdflatex:
>>>
>>> <CODE>
>>> #!/usr/bin/ruby
>>>
>>> file = IO.popen('pdflatex -interaction scrollmode test.tex','r+') #1
>>>
>>> until file.readline.include? 'typein'; end
>>> file.write "a line from RUBY"
>>> file.readlines #2
>>> file.close
>>> </CODE>
>>>
>>> If I run the command from #1 in a sheel it works right: scrolls
>>> "standard" latex asks, and stops for my "\@typein=". After I answer it
>>> continues normally.
>>>
>>> But when I want do the same in Ruby with above code, it hangs out
>>> waiting for input. It looks like #2 causes this, but I don't know why...
>>
>> It's probably because the write buffer for the pipe is not being
>> flushed.  My preferred option to fix this sort of thing is to make the
>> file object synchronous:
>>
>> file = IO.popen(.....)
>> file.sync = true
>>
>> However, you might prefer to explicitly flush things instead:
>>
>> file.write(.....)
>> file.flush
>> ...
>> file.write(.....)
>> file.write(.....)
>> file.flush
>
> One more thing: you may need to insert a newline at the end of the
> strings you write or use #puts instead of #write.  Most interactive
> programs like this expect a newline character to flag the end of data
> entry for a field.
>
> -Jeremy
>
Both your answers works. THX!