c# - C# 中的命令行 CD(更改目录)变体?

标签 c# .net command-line

我想编写一个简单的 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/

相关文章:

c# - MEF 条件导入

bash - 移动 "n"文件,每个文件在 ubuntu 中使用命令行或 bash 移动到特定文件夹

ruby - Git Bash 和 ruby

.net - 什么会导致 GZipStream 压缩数据过多地填充零?

c# - 使用 .NET WebClient 类提交时,PHP 中未收到 POST 值

python - python shell 可以有一些预输入吗?

c# - WPF 中的可移植类库 ICommand 编译错误——不确定如何适本地解决这个问题?

c# - 为什么 ASP.NET Identity 返回 401 而不是重定向到登录页面?

c# - 使用 iTextSharp 生成 PDF

c# - 从 C# : How to properly pass data between managed and unmanaged code 调用非托管 C++ 库 (dll)