C#控制台程序中使用 Process.Start()启动exe,但是却重新打开了一个窗口,如何让其在当前窗口中继续显示

如题,被打开的exe也是控制台程序。
2024-11-29 15:20:18
推荐回答(2个)
回答1:

try
{
Process proc = new Process();
proc.StartInfo.WorkingDirectory = @"C:\Users\Administrator\source\repos\sss\sss\bin\Debug\netcoreapp2.1\";
proc.StartInfo.FileName = " cmd.exe ";
proc.StartInfo.Arguments = @" /c C:\Users\Administrator\source\repos\sss\sss\bin\Debug\netcoreapp2.1\sss.bat";
proc.Start();
proc.Close();
proc.Dispose();
string file = proc.StartInfo.WorkingDirectory + "sss.bat";
Thread.Sleep(300);
Console.WriteLine("程序sss已开启");
Process[] getProcessName = Process.GetProcesses();
foreach (Process pro in getProcessName)
{
if (pro.ProcessName == "dotnet")
{
if (!ht.Contains(pro.Id))
{
ht.Add(pro.Id, file);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString());
}

回答2:

你应该设置你全屏的form 的topmost属性为true了,如果你没设置这个属性,新启动的程序都是在前面的