windows 运行服务后命令提示符关闭太快
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2066376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Command Prompt Closes Too Fast After Running A Service
提问by Bozzy
I have a problem with a service. I have an installed application that runs as a service; when I start that service, a command prompt opens and immediately closes. The program isn't executing properly and I need to see the error output but the command prompt closes too quickly. Is there a way to force the window to remain open? Thanks everyone!
我的服务有问题。我有一个作为服务运行的已安装应用程序;当我启动该服务时,会打开一个命令提示符并立即关闭。程序未正确执行,我需要查看错误输出,但命令提示符关闭得太快。有没有办法强制窗口保持打开状态?谢谢大家!
回答by ComponentBuilder
Put a PAUSE in the batchfile.
在批处理文件中放置一个 PAUSE。
MyApp.exe
PAUSE
That's all
就这样
回答by Hans Passant
Services cannot create console windows, they run in their own session with their own "desktop". Given that you see one, I'd have to guess that you didn't actually create a service. What happened when you tried to install it with InstallUtil.exe?
服务不能创建控制台窗口,它们在自己的会话中使用自己的“桌面”运行。鉴于您看到了一个,我不得不猜测您实际上并没有创建服务。当您尝试使用 InstallUtil.exe 安装它时发生了什么?
This MSDN Library pagehas recommendations to debug a service's OnStart() method.
此MSDN 库页面提供了调试服务的 OnStart() 方法的建议。
回答by Michael Todd
Since a service doesn't allow for user-interaction, could you instead redirect your message to stderr or a file? Or post something to the Event Viewer?
由于服务不允许用户交互,您能否将消息重定向到 stderr 或文件?或者向事件查看器发布一些内容?
回答by Ron Savage
If the service doesn't keep it's own log file, there might be an error visible in the Event Log on that machine. You can open the EventViewer from the Control Panel / Administrative Tools section.
如果服务不保留自己的日志文件,则该机器上的事件日志中可能会显示错误。您可以从控制面板/管理工具部分打开事件查看器。