I have the same issue, it seems the build system leaves that last thing printed to the terminal intact and ends with a character return \r. So the next thing you print simply overrides what’s there. When you invoke the binary directly via ./zig-out/bin/executable it won’t show up, it’s just an issue with ‘zig build’ leaving garbage in your terminal.
You can print a newline at the top of your program if you wish to avoid it. Otherwise it needs a fix in the zig build system (I’m guessing).
it does this so it can overwrite the line repeatedly (update it essentially).
Depending on your system: zig build | cat might fix that since it should detect a pipe instead of a tty and change its formatting to be more basic.
edit this does not work - i’d consider it a bug since programs to be good citizens are supposed to detect if they are going to a tty or not.
wtf: zig appears to write to stderr, but when I redirect stderr to stdout and dump stdout to a file, i get nothing. what am i doing wrong?
> make clean; zig build test > o 2>&1
> ll o
-rw-r--r-- 1 jason jason 0 Jun 2 15:08 o
I get nothing when I redirect:
> make clean; zig build test 2> o2 1> o1
rm -rf zig-out zig-cache *.a *.a.o
> ll o*
-rw-r--r-- 1 jason jason 0 Jun 2 15:12 o1
-rw-r--r-- 1 jason jason 0 Jun 2 15:12 o2
I know I definitely had this bug in the past but now that I’m trying the latest 13-dev release I can’t recreate it. It seems the new progress bar for the build system may have fixed this (on windows 10 fwiw).
Interesting - I’m running it on Ubuntu. Your explanation makes sense though. I’ve been having issues with printing stuff to console ever since I switched to 13.
Come to think of it, I think you’re right - it’s always when doing a command like: zig run main.zig but running a binary directly doesn’t have the same issue.
The most recent released version of zig is 0.12.0 and the tip of master branch is currently 0.13.0-dev.354+0c2cd8381. There has not yet been a 13.0 or 0.13.0 release.