【发布时间】:2014-04-06 16:10:10
【问题描述】:
我有一个旨在执行以下操作的 Windows 服务:
- 监视服务器上的文件夹中的 PDF 文件
- 当文件到达时,运行第三方 exe 将 PDF 转换为 Excel。不生成文本输出。第三方工具只需使用输入文件路径并生成输出 excel 文件。无需启动窗口。无需跟踪会话。
- Windows 服务然后从 Excel 中读取数据,对其进行处理,并将 xml 输出到文件夹中。
所有这些在调试模式下都可以正常工作。但是,当我尝试在本地计算机上以发布模式(使用 installutil)作为服务(而不是在 Visual Studio 中)运行 Windows 服务时,它不起作用。当我附加到进程时,我注意到光标只是挂在 waitforexit 上并且没有生成 excel。由于它可以在调试模式下工作,但不能在发布模式下工作,我怀疑这是权限问题。任何反馈将不胜感激。
已尝试检查“允许服务与桌面交互”。没有帮助。
编辑:更正 - 光标实际上挂在 exeProcess.WaitForExit()
ProcessStartInfo sInfo = new ProcessStartInfo();
sInfo.FileName = ConfigurationManager.AppSettings["FileName"];
sInfo.Arguments = GetArguments();
sInfo.UseShellExecute = false;
sInfo.CreateNoWindow = true;
sInfo.ErrorDialog = false;
sInfo.WindowStyle = ProcessWindowStyle.Hidden;
//sInfo.RedirectStandardError = true; //didn't work
//sInfo.RedirectStandardInput = true; //didn't work
//sInfo.RedirectStandardOutput = true; //didn't work
using (Process exeProcess = Process.Start(sInfo))
{
//StreamWriter inputWriter = exeProcess.StandardInput;
//StreamReader outputReader = exeProcess.StandardOutput;
//StreamReader errorReader = exeProcess.StandardError;
exeProcess.WaitForExit();
}
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
@RickS,在发布问题之前,我已经浏览了这些链接。您对将 Topshelf 与控制台应用程序一起使用有什么建议,以便控制台应用程序可以调用第三方 exe 并将 PDF 文件名传递给它。这行得通吗?
-
是否有任何理由等待命令行实用程序退出?如果您查看即将到来的 pdf 文件的文件夹,那么您可以运行该工具并让它完成工作。并且在一段时间后或通过另一个观察者的通知来处理 excel 文件。
标签: c# .net process windows-services processstartinfo