Created
October 23, 2025 09:55
-
-
Save Coutlaw/4cd5f694fa8fdf784489115afdabe5ef to your computer and use it in GitHub Desktop.
First Zig program, executing bash from zig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| pub fn main() !void { | |
| const allocator = std.heap.page_allocator; | |
| const commands = &[_][]const u8{ "bash", "-c", "echo Hello from Bash" }; | |
| var child = std.process.Child.init(commands, allocator); | |
| try child.spawn(); | |
| const term_sig = try child.wait(); | |
| switch (term_sig) { | |
| .Exited => |code| { | |
| if (code == 0) { | |
| std.debug.print("Bash worked!\n", .{}); | |
| } else { | |
| std.debug.print("Oopsie Whoopsie, we made a fucky wucky: {d}\n", .{code}); | |
| } | |
| }, | |
| else => { | |
| std.debug.print("Don't even know what sorts of fucked up we got to\n", .{}); | |
| }, | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment