I am writing a C program that should able to take and run command prompt commands and then spit out the output to stdout. This is easy enough, as all it takes is system("dir")
which works perfectly and does what you would think it does.
The problem is that I would like this cmd session to be persistent. What does not work but I would like to be able to do is
system("cd ..");
system("dir");
to print the contents of the parent directory. This does not work it seems because the cmd session between the cd call and dir call is not the same, and the cd has no effect on the working directory when we call dir.
Ideally I would like to be able to create a cmd process where I could run commands in it, do other stuff in the program, then continue to run commands and have it be the same cmd process the whole time until I manually close it.
How would I accomplish this?
Edit: This is supposed to run on Windows.