#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main(){
char command[20];
system("dir");
while(1){
printf("\n\n");
scanf("%s", &command);
system(command);
}
return 0;
}
this is my code, it's a console app written in C and I wanna be able to control the cmd prompt of my computer, whenever I run new command like cd..
the path always goes back to where it was before, how do i make it like a process? sorry I'm new to it.
You can't.
The cd
command in typical command-line interpreters is an internal command, i.e. built into the command interpreter itself. This is because the current directory is a property of the process itself, and a child process (which is what system()
creates, in most cases) can't change the current directory of its parent.