@@ -122,6 +122,39 @@ class EnvironmentCache {
122122 std::mutex mutex_;
123123};
124124
125+ std::vector<const char *>
126+ PlatformExecutionPolicy::convertEnvironment (const Command& cmd) {
127+ // Set up environment variables
128+ std::unordered_map<std::string, std::string> env_map;
129+ env_map.insert (cmd.env .begin (), cmd.env .end ());
130+ if (cmd.env_inherit ) {
131+ // Add current environment to env
132+ auto current_env = EnvironmentCache::instance ().get_all ();
133+ env_map.insert (current_env.begin (), current_env.end ());
134+ }
135+ std::vector<const char *> envp;
136+ for (const auto & arg : env_map) {
137+ envp.push_back ((arg.first + " =" + arg.second ).c_str ());
138+ }
139+ envp.push_back (nullptr ); // NULL-terminated
140+
141+ return envp;
142+ }
143+
144+ std::vector<const char *>
145+ PlatformExecutionPolicy::convertArgv (const Command& cmd) {
146+ // Convert command args to C-style argv
147+ std::vector<const char *> argv;
148+ argv.push_back (cmd.executable .c_str ());
149+ for (const auto & arg : cmd.args ) {
150+ argv.push_back (arg.c_str ());
151+ }
152+ argv.insert (argv.begin (), cmd.executable .filename ().c_str ());
153+ argv.push_back (nullptr ); // NULL-terminated
154+
155+ return argv;
156+ }
157+
125158ExecutionResult PlatformExecutionPolicy::execute (const Command& cmd) const {
126159 // Fork process
127160 pid_t pid = fork ();
@@ -151,8 +184,9 @@ ExecutionResult PlatformExecutionPolicy::execute(const Command& cmd) const {
151184 // Open file and redirect stdin (TODO)
152185 }
153186 if (std::holds_alternative<FileTarget>(cmd.stdout_ )) {
154- std::cout << " Redirecting stdout to file \n " ;
187+
155188 const auto & file_target = std::get<FileTarget>(cmd.stdout_ );
189+ std::cout << " Redirecting stdout to file: " << file_target.path .c_str () << std::endl;
156190 // TODO umask
157191 // Open file and redirect stdout
158192 int fd = open (file_target.path .c_str (),
@@ -253,10 +287,7 @@ ExecutionResult PlatformExecutionPolicy::execute(const Command& cmd) const {
253287 }
254288 return ExecutionResult{.exit_code = exit_code, .error_message = std::nullopt };
255289 }
256- return ExecutionResult{.exit_code = platform::EXIT_FAILURE_STATUS ,
257- .error_message = " Fallthrough case reached, pid == 0" };
258- return ExecutionResult{.exit_code = platform::EXIT_FAILURE_STATUS ,
259- .error_message = " Fallthrough case reached, outside of pid checks" };
290+ return ExecutionResult{.error_code = 0 , .error_message = std::nullopt };
260291}
261292ExecutionResult PlatformExecutionPolicy::execute (const Pipeline& pipeline) const {
262293 // Phase 1: No pipeline support yet - just execute first command
0 commit comments