const std = @import("std"); const os = std.os; const io = std.io; // This imports the separate module containing `root.zig`. Take a look in `build.zig` for details. const lib = @import("zesh_lib"); const c = @cImport({ @cInclude("pty.h"); }); pub fn main() !void { const args = os.argv; for (args) |arg| { const a: []const u8 = std.mem.span(arg); std.log.debug("args {s}", .{a}); } // const cmd: []const u8 = std.mem.span(args[1]); // if (std.mem.eql(u8, cmd, "client")) { // try run_client(); // } else if (std.mem.eql(u8, cmd, "server")) { // try run_server(); // } else { // return error.InvalidArg; // } const master_fd: [*c]c_int = 0; var pid: c.pid_t = 0; pid = c.forkpty(master_fd, null, null, null); if (pid == -1) { std.debug.print("forkpty failed\n", .{}); return; } if (pid == 0) { const ag = [_:null]?[*:0]const u8{"/usr/bin/fish"}; // child process std.debug.print("This is the child process with PID: {}\n", .{os.linux.getpid()}); const err = std.posix.execvpeZ(ag[0].?, &ag, std.c.environ); std.log.err("exec failed: {}", .{err}); } else { // parent process var status: u32 = 0; std.debug.print("This is the parent process with PID: {} and child PID: {}\n", .{ os.linux.getpid(), pid }); const wait_result = os.linux.waitpid(pid, &status, 0); if (wait_result != 0) { std.debug.print("Command returned {}.\n", .{wait_result}); } } } // fn run_server() !void { // std.log.debug("server is running", .{}); // } // // fn run_client() !void { // std.log.debug("client is running", .{}); // }