#redirecting stdout/stderr (or similar) to file ?
1 messages · Page 1 of 1 (latest)
wdym?
as in redirect it for the current process? or make a new process and redirect its stdout/err to a file?
for the current process. I'm embedding lua and writing a minimal test library to test out code I have which will be both in lua (same process) and zig.
And I want to capture that output (stdout, stderr) and selectively display it for failing tests, hence the idea
I think this is what dup2 does on posix systems
and windows seems to have SetStdHandle
but apparently that doesnt actually update the fd, it just makes future calls to GetStdHandle give the new one
so if an app caches the file handle windows gives it for stdout/stderr, it wont update it like it would on linux
so that might be an issue
Fun.
Actually, a thing I'm struggling with right now. I am pondering writing a posix and a windows path.
But for the windows path, my struct will need different fields than for the posix path.
How do I express such a struct ?
(I am guessing something with comptime and std.builtin.os.tag
posix_field: if (posix) u8 else noreturn,
windows_and_posix_field: if (windows) u32 else u64,
etc
you can just use it like that as long as posix and windows are comptime known
noreturn ? so what.. the field won't be present at all if we are on a non-posix platform ?
note that using noreturn as the type means that it cant be accessed
if you try to access a field thats a noreturn, itll be a compile error
if you just want it to be optimized out, you can make it void or u0 (or any other zero-width-type)
yep!
it wont exit and it would be an error to access it
interesting. I was hunting around (a little!) in the stdlib for something like this
I cant really think of any specific spot unfortunately
but std.fs and std.io probably use it if I had to guess