ssadler / hawk

Awk for Hoodlums
BSD 3-Clause "New" or "Revised" License
35 stars 2 forks source link

can't redirect with -w #55

Closed gelisam closed 11 years ago

gelisam commented 11 years ago

Okay, this is really strange, and I have no idea how we can be causing this.

Usually, everything we print can equivalently be redirected into a file:

> hawk [1..3] > out
> cat out
1
2
3
> hawk [1..3]
1
2
3

But with the flag -w, this doesn't work?!

> printf "1 2 3\n4 5 6\n7 8 9" | hawk -w 'reverse' > out
> cat out
> printf "1 2 3\n4 5 6\n7 8 9" | hawk -w 'reverse'
3       2       1
6       5       4
9       8       7

An example with -l, to show that this is really unique to -w:

> printf "1 2 3\n4 5 6\n7 8 9" | hawk -l 'reverse' > out
> cat out
7 8 9
4 5 6
1 2 3
> printf "1 2 3\n4 5 6\n7 8 9" | hawk -l 'reverse'
7 8 9
4 5 6
1 2 3
melrief commented 11 years ago

Also -m suffers the same problem. Honestly, I don't know what the hell is going on, but the problem is probably in how hawk splits the lines.

melrief commented 11 years ago

Found the bug, I'm testing my fix.

melrief commented 11 years ago

Ok I have pushed a new version which flush stdout at the end. It seems to work (your example at least). I still don't have any explanation on why we need to flush stdout only when redirecting...but luckily the first thing that I try when something is not printed in output by a Haskell program is flushing.