So I'm programming pipe in C (to support multiple pipes) Currently I'm testing it with hardcod command. I tried to change the CD command to replace the existing working directory and pwd command to display the new directory. But this does not work for me: The CD does not change the work directory and displays the old directory of my debug folder in the project root. If you explain me because of this problem then I would be very thankful thank you!
Here is the code
int main (int argc, const char * argv []) {char * cd [] = {"cd", "/ user / user / / "Desktop", NULL} four * PWD [] = {"PWD", NULL}; four ** CMD [] = {CD, PWD, NOUL}; loop_pipe (cmd); return 0;} zero-loop_pip ( Four *** CMD {int p [2]; Pid_t pid; int fd_in = 0; while (* CMD! = Null) {pip (p); if ((pid = fork ()) == -1) { Exit (EXIT_FAILURE);} and if (pid == 0) {dup2 (fd_in, 0); // Change the input according to the old one (* (CMD + 1)! = NULL) dup2 (p [1], 1 ); Close (p [0]); Execvp ((* CMD) [0], * CMD); Cass (EXIT_FAILURE);} and (wait (tap); close (p [1]); fd_in = p [0]; // save input for next command cmd ++;}}}}
cd
is not a program in shell, as a built-in What will happen if this is not the case: The new hair process changes the directory and then immediately comes out, there is no continuous change. Parents and children do not share task work directories.
I suspect that your goal is to actually replace directories per , but if you wanted, you have to do this chdir ()
Use the call to "manually" in your original process.
No comments:
Post a Comment