Last active
July 24, 2024 17:57
-
-
Save 50n1cd347h9/c2fb42be2335101ce4f6e008461ca0b8 to your computer and use it in GitHub Desktop.
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 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