Thanks to all for the thorough replies!
Of course I'm not really interested in interaction with od; I just used it
as an example of a program that reads input and produces output accordingly.
I wanted to interface to a program (gap) that flushes its output on
terminals, but seemingly not on pipes.
That leaves 2 options: either change gap so that it doesn't buffer its
output, or run the process on a pseudo-tty.
In all cases, the problem isn't with Julia :)
On Sunday, 28 June 2015 22:39:36 UTC+2, Jameson wrote:
>
> yes, it is the fault of `od`. you can see this by using `cat` instead and
> observing that it works. if you play around with the thresholds in `od`,
> you will observe that it is doing block-buffering of 4096 byte chunks when
> the input is a pipe.
>
> Unless you turn on write buffering (with `buffer_writes(si)`), the `write`
> function implicitly calls `flush`, and will block the task until the write
> completes (the actual `flush` function is a no-op). Therefore, it's best to
> call write in a separate task if you are processing both ends of the pipe:
>
> julia> (so,si,pr) = readandwrite(`od`)
> (Pipe(open, 0 bytes waiting),Pipe(open, 0 bytes waiting),Process(`od`,
> ProcessRunning))
>
> julia> @async write(si,repeat("test\n",10000))
> Task (done) @0x00007fe37aa0daa0
>
> (note, the line_buffered property has no effect)
>
> Note that Base.readavailable returns a random, non-zero number of bytes,
> which is presumably not what you want?
>
> julia> Base.readavailable(so)
> 135168-element Array{UInt8,1}:
> ...
> julia> Base.readavailable(so)
> 61440-element Array{UInt8,1}:
> ...
>
> In order to get the full output, you need to instead call:
> julia> close(si)
> julia> readall(so)
>
>
> On Sun, Jun 28, 2015 at 9:08 AM Jeff Waller <[email protected]
> <javascript:>> wrote:
>
>>
>>
>> On Saturday, June 27, 2015 at 5:03:53 PM UTC-4, [email protected] wrote:
>>>
>>> Is your od program flushing its output? Maybe its stuck in its internal
>>> buffers, not in the pipe.
>>>
>>
>> nah man, if it's it's od, it's not going to do that, the only thing
>> simpler is cat; I suppose you could try cat.
>>
>> What happens when you do something like this?
>>
>> *julia> **fromStream,toStream,p=readandwrite(`cat`)*
>>
>> *(Pipe(open, 0 bytes waiting),Pipe(open, 0 bytes waiting),Process(`cat`,
>> ProcessRunning))*
>>
>>
>> *julia> **toStream.line_buffered*
>>
>> *true*
>>
>>
>> *julia> **toStream.line_buffered = false*
>>
>> *false*
>>
>>
>> *julia> **fromStream.line_buffered = false*
>>
>> *false*
>>
>>
>> *julia> **write(toStream,"x")*
>>
>> *1*
>>
>>
>> *julia> **readavailable(fromStream)*
>>
>> *1-element Array{UInt8,1}:*
>>
>> * 0x78*
>>
>