gpt4 book ai didi

c# - 如何从我的 C# 代码运行 EXE 文件?

转载 作者:IT王子 更新时间:2023-10-29 03:32:27 24 4
gpt4 key购买 nike

我的 C# 项目中有一个 EXE 文件引用。如何从我的代码中调用该 EXE 文件?

最佳答案

using System.Diagnostics;

class Program
{
static void Main()
{
Process.Start("C:\\");
}
}

如果您的应用程序需要 cmd 参数,请使用如下内容:

using System.Diagnostics;

class Program
{
static void Main()
{
LaunchCommandLineApp();
}

/// <summary>
/// Launch the application with some options set.
/// </summary>
static void LaunchCommandLineApp()
{
// For the example
const string ex1 = "C:\\";
const string ex2 = "C:\\Dir";

// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "dcm2jpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;

try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}
}
}

关于c# - 如何从我的 C# 代码运行 EXE 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9679375/

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