首页 > 解决方案 > 我试图从 c# windows 应用程序打开命令行以运行 exe 文件,但它只打开 cmd 而没有运行命令

问题描述

这是我试图打开命令行的代码。我想要做的是运行命令`“client_server.exe”+ received_ip; 在 cmd 但它只打开窗口而不运行命令。有人对我有解决方案吗?

var process = new Process();
                    var startInfo = new ProcessStartInfo();
                    //startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                    startInfo.FileName = "cmd.exe";
                    startInfo.Arguments = @"client_server.exe " + received_ip;
                    process.StartInfo = startInfo;
                    process.Start();

                    process.WaitForExit();

标签: c#cmd

解决方案


你试过UseShellExecute房产吗?

var process = new Process();
var startInfo = new ProcessStartInfo();

startInfo.FileName = "client_server.exe";
startInfo.Arguments = received_ip;

startInfo.UseShellExecute = true;

process.StartInfo = startInfo;
process.Start();

process.WaitForExit();

推荐阅读