我使用 GHC 7.6.3
32 位
在 Windows Server 2008
上编译了一个程序。我试图在启动时通过 Windows 内的服务运行它(并且最好保持运行)。为此,我已使用以下命令成功创建了一个服务
sc create stworker binPath= "C:\Users\vagrant\Desktop\worker.exe"
我遇到的问题是,当我尝试启动服务时,我收到以下错误(见下图)。
当我双击可执行文件时,它运行良好。所以不确定为什么 Windows 不允许运行该服务。
我认为这不是 GHC
的问题。我假设 GHC 编译为 native 代码而不是 MSIL。
那么有什么想法为什么我无法将可执行文件作为服务运行吗?
最佳答案
正如评论中提到的,您需要实际实现 Win32 服务 API,以使您的程序充当 Windows 服务,您可以使用 Win32-services
来完成此操作。包。
还有一个包装包Win32-services-wrapper
我写的旨在提供一些样板文件并处理日志记录,以便定义服务如下所示:
main =
defineService $
Service {
serviceName = "Service",
-- Start the service given a debug handle to write to.
-- Make sure not to use stdout or stderr as they don't exist.
-- Any state needed by serviceStop can be returned here -
-- the Service type takes the type of the state as a type parameter
serviceStart = \debugHandle -> ...,
-- Stop the service given the service state returned by serviceStart
serviceStop = \serviceState -> ...
}
darcsden
中有一个使用它的真实例子.
关于windows - 将 GHC 创建的 Windows 可执行文件作为服务运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22748419/