In the Zig build system, how to pipe a file to a process's stdin?

Hey, I’m new to Zig and trying to figure out how to port some Makefiles to its build system, and I’ve gotten stuck pretty quickly. There doesn’t seem to be much documentation on how to call executables from the Zig build system.

What I’m trying to do is build an executable some-exe, then, as another step, generate a C file by running that execuable with a file piped to it (some-exe < file.txt > out.c).

const someExe = b.addExecutable("some-exe", "main.c");
someExe.setTarget(target);
someExe.setBuildMode(mode);
someExe.linkLibC();

const generated = someExe.run()
// ... now how do I pipe a file to this?
1 Like

:confused: Well, at least there’s an issue for it. In the meantime, it seems like an alternate solution would be… write a shell script and call it with b.addSystemCommand, passing in both the exe and the piped file?

Does main.c accept a file name as an input? If so you could use addFileSourceArg.

I’ve got this piece of code you can use for now, I use it to generate C files from m4. Sorry @andrewrk ill PR a patch eventually :stuck_out_tongue:

1 Like