Reputation: 1648
I want to write a simple C# console application to change the current directory of the command line to a directory the application works out. Looking through MSDN System.IO.Directory.SetCurrentDirectory looks ideal for this until I saw in the remarks that:
'When the application terminates, the working directory is restored to its original location (the directory where the process was started).'
And sure enough when I tried this in a test application it didn't work. Does anyone have any idea how to implement a CD variant in C#?
Upvotes: 4
Views: 2130
Reputation: 15811
You could write a wrapper batch script:
@ECHO OFF
FOR /F "tokens=*" %%i in ('someapp.exe') do SET TOOLOUTPUT=%%i
CD %TOOLOUTPUT%
I haven't tested this, but it should get you where you are trying to go.
Upvotes: 3
Reputation: 354506
I doubt that is possible, as you are just setting the current working directory for your program instead of the cmd process that spawned it.
Upvotes: 1