C# 如何在 process.arguements 中使用目录空格?
创建的程序利用第三方工具生成日志文件。
但是,为该工具提供的参数需要目录位置中的各种文件作为生成日志的一部分。因此,将使用 @"-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();
The program created utilizes a 3rd party tool to generate a log file.
However the arguments provided for the the tool requires various files from Directory locations as part of generating the logs. Therefore the main argument of @"-r C:\test\ftk\ntuser.dat -d C:\System Volume Information\" + restoreFolder.Name + " -p runmru";
would be used to generate the logs.
May someone advise on how to make the arguments of "C:\System Volume Information\" be processed by the system with the white spaces in placed? Thanks!
The codes:
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要通过向其附加
\
(\"
) 来转义"
- 对于普通字符串,或者将它们加倍 (" "
) 用于逐字字符串文字(以@
开头的字符串):You need to escape the
"
by appending a\
to them (\"
) - for normal strings, or doubling them (""
) for verbatim string literals (those starting with@
):将该路径用双引号引起来:
Wrap that path in double quotes:
也许
应该是
Perhaps
should be
如果我正确理解了这个问题,您可以用引号将名称括起来:
If I correctly understood the question, you can wrap the name with quotes:
您确实需要使用 string.Format 和 Path 类:
可以重写为更清晰,如下所示:
You really need to use a string.Format along with the Path class:
can be rewritten to be a lot cleaner as follows: