如何用c#中的参数调用exe? [英] How to call exe with parameters in c#?
本文介绍了如何用c#中的参数调用exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要调用此方法:log.exe port13.dat StringTable> porttest.txt
Need to call this : log.exe port13.dat StringTable > porttest.txt
推荐答案
您可以使用.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.
这篇关于如何用c#中的参数调用exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文