Created
July 24, 2024 15:44
-
-
Save 50n1cd347h9/9499ca9d79e366a5e4bb6cea26ef0814 to your computer and use it in GitHub Desktop.
How to spawn a process
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"); | |
const Child = std.process.Child; | |
const ArrayList = std.ArrayList; | |
pub fn main() !void { | |
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
const allocator = gpa.allocator(); | |
defer { | |
const deinit_status = gpa.deinit(); | |
_ = deinit_status; | |
} | |
// var stdout_buf = ArrayList(u8).init(allocator); | |
// defer stdout_buf.deinit(); | |
// var err_buf = ArrayList(u8).init(allocator); | |
// defer err_buf.deinit(); | |
const command = [_][]const u8{ "ls", "-la" }; | |
var child = Child.init(&command, allocator); | |
try child.spawn(); | |
// try child.collectOutput(&stdout_buf, &err_buf, 0x1000); | |
const res = try child.wait(); | |
std.debug.print("{!}\n", .{res}); | |
// std.debug.print("stdout: {s}\nerr: {s}\n", .{ stdout_buf.items, err_buf.items }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment