I could be wrong here. A process has a notion of WorkingDirectory which can
be set, or if null, set to the parent process PWD. After that, the process
app may use that var or not. Shells like cmd.exe use that to set its *own
PWD internal var. CD gets and sets this internal var, but I am not sure
this also updates the ProcessInfo.WorkingDirectory var. So I think to get
the current dir of the shell, you would need to call some api on cmd.exe
itself (if you did not want to use echo %cd%). Maybe there is some com api
for it. The other issue (maybe) is when do you know the command that was
sent to the shell, via std input, is actually complete so you can update the
CWD in your UI? All your reading is an output stream of console output
(e.g. text), you don't really know when a script or exe is finished by
cmd.exe. cmd.exe knows, because it can wait for process exit and then
display the prompt again. But we just have an output stream that does not
tell you that. There must be some tricks as I think people have written UI
shell wrappers around cmd (I tried once and got stuck on the same issues).
Interested in a solution as well. Cheers and good luck.
--
William Stacey [MVP]
| Hi.
|
| I'm writing an application in C# that runs a "cmd.exe" in another
| process.
|
| I need to get the working directory of the process without having to
| resort to issueing "echo %CD%" to the cmd process.
|
| Can anyone help me?
|
| I'm going nuts trying to find a way to do this.
|
| Cheers,
| /Blitr
|