简体   繁体   English

从命令行在后台运行程序

[英]Running program in background from command line

So I have a console application that runs a command line process and then closes. 因此,我有一个控制台应用程序,该应用程序运行命令行过程,然后关闭。 For that second that the process gets called, I can see the window of the process pop up then disappear. 在该过程被调用的那一刻,我可以看到该过程的窗口弹出然后消失。

Is it possible to either: 是否可以:

  • Run the other process in the background 在后台运行其他进程
  • Run the other process minimized so that it still shows on the taskbar but not on the screen. 运行最小化的其他进程,使其仍显示在任务栏上,而不显示在屏幕上。

My code currently: 我的代码当前:

var proc = new Process();
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardInput = true;
proc.Start();

proc.StandardInput.WriteLine(@"Navigate to Correct Folder");
proc.StandardInput.WriteLine(@"Run Outside Program");

Add that line : 添加该行:

 proc.StartInfo.Arguments = " /c;

And that one : 那一个:

proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

I suspect that you're actually seeing the window of your console application, and not the process you're launching. 我怀疑您实际上是在看到控制台应用程序的窗口,而不是正在启动的进程。 Change the output type to Windows Application. 将输出类型更改为Windows应用程序。 在此处输入图片说明

Here 'sa solution that will allow you to show the console still if you need to, for example, if something goes wrong and you want to alert the user. 是一个解决方案,可让您在需要时仍然显示控制台,例如,如果出现问题并且想要警告用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM