我想编写一个简单的 C# 控制台应用程序,将命令行的当前目录更改为应用程序运行的目录。通过 MSDN 查看 System.IO.Directory.SetCurrentDirectory看起来很理想,直到我在评论中看到:
'When the application terminates, the working directory is restored to its original location (the directory where the process was started).'
果然,当我在测试应用程序中尝试这个时,它没有工作。有谁知道如何在 C# 中实现 CD 变体?
最佳答案
您可以编写包装器批处理脚本:
@ECHO OFF
FOR /F "tokens=*" %%i in ('someapp.exe') do SET TOOLOUTPUT=%%i
CD %TOOLOUTPUT%
我还没有测试过这个,但它应该可以让你到达你想去的地方。
关于c# - C# 中的命令行 CD(更改目录)变体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/836558/