Process.execv I don't understand

solution

	/// callPgm( pgm, module)  ex: APPTERM (libVte)   module ex: Exemple
	pub fn callPgm(pgm : [] const  u8, module : [] const u8) ErrForms ! void {


		const prog  = std.fmt.allocPrint(utl.allocUtl,"./{s}",.{pgm}) catch unreachable;
		defer utl.allocUtl.free(prog);

		const cmd  = std.fmt.allocPrint(utl.allocUtl,"./{s}",.{module}) catch unreachable;
		defer utl.allocUtl.free(cmd);

		// Retrieval of the working library.
		var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
		const cwd = std.os.getcwd(&buf) catch unreachable;

		// Initialization of the process (calling a program, and parameter).
		const allocChild = std.heap.page_allocator;
		const args : [2][]const u8= .{prog,cmd };
		var CallModule : std.ChildProcess = std.ChildProcess.init(args[0..], allocChild) ;

		//The set of modules is located in the manager's library, for example: (APPTERM).
		CallModule.cwd = cwd;

		// Execution and suspension of the caller.
		const childTerm = std.ChildProcess.spawnAndWait(&CallModule) catch unreachable;

		// Error handling is provided to the calling procedure.
		switch (childTerm) {
		.Exited => |code| { if (code != 0) return ErrForms.Module_Invalid ; },
		else => unreachable,
		}

	}
1 Like