gpt4 book ai didi

c# - 如何在 C# 中执行带有参数的命令行参数?

转载 作者:行者123 更新时间:2023-11-30 13:27:03 25 4
gpt4 key购买 nike

我正在尝试使用名为 UltraCompare 的第三方比较工具来比较两个文件夹。下一行调用该程序并打开两个文件...但这除了打开它们之外什么都不做,而且对于文件夹它不能正常工作。

Process.Start("C:\\Program Files\\IDM Computer Solutions\\UltraCompare\\uc.exe", 
textBoxContents1 + " " + textBoxContents2);

我想使用以下命令行调用打开两个文件夹,对它们进行比较,并将结果存储在 output.txt 中:uc -d -dmf "c:\dir1""c :\dir2"-o "c:\output.txt"

此外,我需要为文件夹使用变量,而不是对路径进行硬编码。

我如何将它应用到我的 C# 代码中?

更新 1:

我已经根据您的建议修改了我的代码:

var p = new System.Diagnostics.Process();
p.StartInfo.FileName = "C:\\Program Files\\IDM Computer Solutions\\UltraCompare\\uc.exe";
p.StartInfo.Arguments = String.Format("-d -dmf \"{0}\" \"{1}\" -o c:\\output2.txt",
textBoxContents1, textBoxContents2);
p.Start();

我想知道为什么包含参数的第三行仍然不起作用...

更新 2:

我的错误。它现在正在工作!只是不显示 UltraCompare 中的文件夹,但它仍在写入和保存输出。谢谢大家!

最佳答案

你可以使用

yourProcess.StartInfo.Arguments = " .....";

示例

var p = new System.Diagnostics.Process();
p.StartInfo.FileName = "C:\\Program Files\\IDM Computer Solutions\\UltraCompare\\uc.exe";
p.StartInfo.Arguments = String.Format("-d -dmf {0} {1} -o c:\output.txt",textBoxContents1, textBoxContents2);
p.Start();

关于c# - 如何在 C# 中执行带有参数的命令行参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14587562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com