Skip to content

Instantly share code, notes, and snippets.

@50n1cd347h9
Last active July 24, 2024 17:57
Show Gist options
  • Save 50n1cd347h9/c2fb42be2335101ce4f6e008461ca0b8 to your computer and use it in GitHub Desktop.
Save 50n1cd347h9/c2fb42be2335101ce4f6e008461ca0b8 to your computer and use it in GitHub Desktop.
const std = @import("std");
const c = std.c;
const fs = std.fs;
const Child = std.process.Child;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const fd = try fs.cwd().createFile("hoge", .{});
defer {
fd.close();
_ = gpa.deinit();
}
_ = c.close(1); // close stdout
_ = c.dup(@as(c.fd_t, @intCast(fd.handle)));
const command = [_][]const u8{"cat"};
var child = Child.init(&command, allocator);
try child.spawn();
const res = try child.wait();
std.debug.print("{!}\n", .{res});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment