C# 从 Windows 窗体运行 .exe 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11635856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 18:36:24  来源:igfitidea点击:

Running a .exe application from Windows Forms

c#vb.netwindows-forms-designervisual-c#-express-2010

提问by Retry

I have an application that I run on the command prompt as follows:

我有一个在命令提示符下运行的应用程序,如下所示:

C:\some_location> "myapplication.exe" headerfile.h

I want to create a Windows Forms application where the user can specify the location of the executable and also the header file so that the Windows Forms application can do this for him/her, and the user wouldn't have to go to the command line and do it.

我想创建一个 Windows 窗体应用程序,用户可以在其中指定可执行文件的位置以及头文件,以便 Windows 窗体应用程序可以为他/她执行此操作,而用户不必转到命令行并做到这一点。

How can I do this?

我怎样才能做到这一点?

采纳答案by Jaime Torres

You need to use the Processclass:

您需要使用Process该类:

Process.Start(@"C:\some_location\myapplication.exe");

For arguments:

对于参数:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\some_location\myapplication.exe";
startInfo.Arguments = "header.h";
Process.Start(startInfo);

Obviously you can pull these names/arguments from text boxes.

显然,您可以从文本框中提取这些名称/参数。

回答by Aghilas Yakoub

You can try with this code:

您可以尝试使用以下代码:

ProcessStartInfo startInfo = new ProcessStartInfo("yourExecutable.exe");

startInfo.Arguments = "header.h"; // Your arguments

Process.Start(startInfo);

回答by Bharat

See ProcessStartInfo.UseShellExecute. This page will provide you with the full information about the .exe process information.

请参阅ProcessStartInfo.UseShellExecute。此页面将为您提供有关 .exe 进程信息的完整信息。

Another way that I used is:

我使用的另一种方法是:

ProcessStartInfo objProcess = new ProcessStartInfo(@"Yours .exe path");
objProcess.UseShellExecute = false;
objProcess.RedirectStandardOutput = true;
Process.Start(objProcess);

And it's working fine.

它工作正常。