更新时间:2022-11-27 10:03:35
您可以使用.NET 流程 [ ^ ]运行此类命令的类...
You may use .NET Process[^] class to run such command...
Process.Start("log.exe", "port13.dat");
通常,对于每次调用外部程序,都使用Process和ProcessStartInfo类。如果为特定文件类型设置了默认程序,您甚至可以直接调用该进程,只能使用文件名。 Process.Start(test.txt)会在我的电脑上打开Notepad ++。
对于你的特殊问题:
In general, for every call to outside program, you use Process and ProcessStartInfo classes. If there is a default program set for particular file type you could even call the process directly, only with file name. Process.Start("test.txt") would open Notepad++ on my computer for example.
For your particular problem:
using System;
using System.Diagnostics;
public class Processing
{
public static void Main()
{
Process p = new Process();
p.StartInfo.FileName = "log.exe";
p.StartInfo.Arguments = "port13.dat StringTable > porttest.txt";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit(); // This waits until the program called is closed
Console.WriteLine("Output:");
Console.WriteLine(output);
}
}
如果这有帮助,请花时间接受解决方案,以便其他人可以找到它。谢谢。
If this helps, please take time to accept the solution so that others may find it. Thank you.