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.
我弄清楚如何启动一个过程。但我现在的问题是控制台窗口(在这种情况下是7z)弹出最前面阻挡我的视线并移除我的焦点打断我的句子或我/我每隔几秒钟做一次。它非常烦人,我如何防止这种情况发生。我认为CreateNoWindow解决了这个问题,但它没有。
NOTE: sometimes the console needs user input (replace file or not). So hiding it completely may be a problems a well.
注意:有时控制台需要用户输入(替换文件或不替换)。完全隐藏它可能是个问题。
This is my current code.
这是我目前的代码。
void doSomething(...)
{
myProcess.StartInfo.FileName = ...;
myProcess.StartInfo.Arguments = ...;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
myProcess.WaitForExit();
}
4 个解决方案
#1
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:\test.exe"
process.StartInfo.Arguments = "--test";
// Go
process.Start();
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#控制台应用程序中使用它来启动另一个进程,它会阻止应用程序在单独的窗口中启动它,而是将所有内容保存在同一个窗口中。
#2
@galets In your suggestion, the window is still created, only it begins minimized. This would work better for actually doing what acidzombie24 wanted:
@galets在你的建议中,窗口仍然是创建的,只是它开始最小化。这对于实际做yogzombie24想要的更好:
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
#3
Try this:
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
#4
I'll have to double check, but I believe you also need to set UseShellExecute = false
. This also lets you capture the standard output/error streams.
我必须仔细检查,但我相信你还需要设置UseShellExecute = false。这也可以捕获标准输出/错误流。
#1
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:\test.exe"
process.StartInfo.Arguments = "--test";
// Go
process.Start();
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#控制台应用程序中使用它来启动另一个进程,它会阻止应用程序在单独的窗口中启动它,而是将所有内容保存在同一个窗口中。
#2
@galets In your suggestion, the window is still created, only it begins minimized. This would work better for actually doing what acidzombie24 wanted:
@galets在你的建议中,窗口仍然是创建的,只是它开始最小化。这对于实际做yogzombie24想要的更好:
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
#3
Try this:
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
#4
I'll have to double check, but I believe you also need to set UseShellExecute = false
. This also lets you capture the standard output/error streams.
我必须仔细检查,但我相信你还需要设置UseShellExecute = false。这也可以捕获标准输出/错误流。