exectd/tests/03_shell.c

25 lines
714 B
C
Raw Normal View History

#include "../include/exectd.h"
int main() {
2024-11-23 15:46:38 +00:00
// Arguments for the ls command
char *argv[] = {"ls", "-l", "-a", NULL};
// Custom environment variables
char *envp[] = {
"MY_ENV_VAR=example",
"PATH=/usr/bin:/bin", // Ensure PATH is set for executable lookup
NULL
};
int fd = ext_open("tests/bin/stdout_dup", O_WRONLY | O_CREAT);
int fd2 = ext_open("tests/bin/stderr_dup", O_WRONLY | O_CREAT);
2024-11-23 15:46:38 +00:00
int status = shell_job("/bin/ls", argv, envp, fd, fd2);
if (status != 0) {
// Handle error
printf("Shell job returned error code: %d\n", status);
}
// Code here will run after the child process has finished
return 0;
}