Is it possible to change the directory in the calling CMD console from inside a C++ program on Windows?
I know there are many ways to change the working directory in the scope of a program, e.g. using _chdir()
, but I would like directory change to be preserved when the program has exited.
I would like the behavior to be something like:
C:\Some\Path>MyProgram.exe
C:\Some\Other\Path>
(similar to calling cd
inside the console)
One solution could be to wrap the program in a .bat
file and then use output of the program as input to the cd
command. However, I would like if that was not necessary.