在不干扰控制台窗口的情况下在 C# 中启动进程 [英] Launching process in C# Without Distracting Console Window

查看:21
本文介绍了在不干扰控制台窗口的情况下在 C# 中启动进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何启动一个进程.但我现在的问题是控制台窗口(在本例中为 7z)弹出最前面,挡住了我的视线并移开了我的注意力,打断了我的句子或每隔几秒钟我正在做的事情.它非常烦人,我如何防止这种情况发生.我以为 CreateNoWindow 可以解决这个问题,但没有.

I figure out how to launch a process. But my problem now is the console window (in this case 7z) pops up frontmost blocking my vision and removing my focus interrupting my sentence or w/e i am doing every few seconds. Its extremely annoying, how do i prevent that from happening. I thought CreateNoWindow solves that but it didnt.

注意:有时控制台需要用户输入(是否替换文件).所以把它完全隐藏起来可能是一个问题.

NOTE: sometimes the console needs user input (replace file or not). So hiding it completely may be a problems a well.

这是我当前的代码.

void doSomething(...)
{
    myProcess.StartInfo.FileName = ...;
    myProcess.StartInfo.Arguments = ...;
    myProcess.StartInfo.CreateNoWindow = true;
    myProcess.Start();
    myProcess.WaitForExit();
}

推荐答案

如果我没记错的话,这对我有用

If I recall correctly, this worked for me

Process process = new Process();

// Stop the process from opening a new window
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

// Setup executable and parameters
process.StartInfo.FileName = @"c:	est.exe"
process.StartInfo.Arguments = "--test";

// Go
process.Start();

我一直在 C# 控制台应用程序中使用它来启动另一个进程,它阻止应用程序在单独的窗口中启动它,而是将所有内容都保留在同一个窗口中.

I've been using this from within a C# console application to launch another process, and it stops the application from launching it in a separate window, instead keeping everything in the same window.

这篇关于在不干扰控制台窗口的情况下在 C# 中启动进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆