How to make console program to disappear and work

2019-04-09 22:39发布

How can I make console program disappear and work in the background? I mean, I don't want to see the program, but I want to see it running in the task manager.

Thanks.

6条回答
The star\"
2楼-- · 2019-04-09 23:21

Assuming a MS Windows XP environment:

My suggestion would be to consider making a Windows Service to do what you are asking, though another possibility would be to set something up within msconfig to run the program at startup or in the startup group within the "Start->All Programs->StartUp" section.

If you are on a Mac, Linux or some other O/S, there may exist a similar function to act as a place to run programs within the background.

查看更多
爷的心禁止访问
3楼-- · 2019-04-09 23:23

Assuming you cannot modify the console application and make it a windowless application you could create a windowless application that launches the console program and redirects all the standard input and output streams to "dummy" streams.

查看更多
Juvenile、少年°
4楼-- · 2019-04-09 23:25

You could alternatively make one that goes to the system tray. This would also allow you to add a Kill Process directly from the system tray instead of going to the task manager. In .NET I have used the following: http://www.developer.com/net/csharp/article.php/3336751

This may offer a few advantages.

查看更多
Ridiculous、
5楼-- · 2019-04-09 23:29

On Windows use ShowWindow(FindWindowA("ConsoleWindowClass", NULL), false) to hide the console window. It will still be running in the background and is not visible on the taskbar.

However you will have to run a task manager like Taskmgr.exe to find it and shut it down.

#include <windows.h>  
#include <iostream>     
using namespace std;


int main () {   
    ShowWindow(FindWindowA("ConsoleWindowClass", NULL), false);
    while(true) {
                 // Do your hidden stuff here
    }   
return 0;
}
查看更多
祖国的老花朵
6楼-- · 2019-04-09 23:31

Assuming Windows and .NET:

You could set its output type to "Windows Application", and it will not open the console window....

Or you could create a Windows Service...

查看更多
We Are One
7楼-- · 2019-04-09 23:43

If you are using Windows try

start command.exe

If you are using *nix

nohup command
查看更多
登录 后发表回答