C# 如何在 process.arguments 中使用目录空白?

标签 c# process directory arguments

创建的程序利用第 3 方工具生成日志文件。

但是,为该工具提供的参数需要来自目录位置的各种文件作为生成日志的一部分。因此,将使用 @"-r C:\test\ftk\ntuser.dat -d C:\System Volume Information\"+ restoreFolder.Name + "-p runmru"; 的主要参数生成日志。

有人可以建议如何让系统处理“C:\System Volume Information\”的参数并放置空格吗?谢谢!

代码:

            Process process = new Process();
            process.StartInfo.FileName = @"C:\test\ftk\ripxp\ripxp.exe";
            process.StartInfo.Arguments = @"-r C:\test\ftk\ntuser.dat -d C:\System Volume Information\" + restoreFolder.Name + " -p runmru";
            process.StartInfo.CreateNoWindow = false;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardError = true;
            process.Start();

最佳答案

您需要通过向它们附加 \ (\") 来转义 " - 对于普通字符串,或将它们加倍 ("") 对于逐字字符串文字(那些以 @ 开头的):

process.StartInfo.Arguments = @"-r C:\test\ftk\ntuser.dat -d ""C:\System Volume Information\" + restoreFolder.Name + @""" -p runmru";

关于C# 如何在 process.arguments 中使用目录空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4441212/

相关文章:

c# - 当我们在 C# 中初始化一个字符串时会发生什么?

java - Sleeping Professor 中的信号量 代码追踪有问题吗?

java - JFrame 可以显示进程吗?

java - 创建具有读写访问权限的新文件夹

c# - 使用 LINQ 解析内部双字典?

c# - 事件链/代理到原始对象

python - 用python遍历一个ftp文件夹

python - 如何在运行时更改目录并将文件存储在不同位置

c# - Microsoft.Test.CommandLineParsing 这是哪个 dll

objective-c - 使用 getrusage