运行一个由C#Windows服务应用程序开发的python脚本
我编写了一个执行python脚本的控制台应用程序。现在我尝试将控制台应用程序转换为Windows服务。Windows服务在没有脚本propper(事件日志中的loggin)的情况下工作。服务在启动ProcessStartInfo时停止
public string Run()
{
_pySkript.WorkingDirectory = _workinDirectory;
_pySkript.FileName = _pythonPath;
_pySkript.Arguments = string.Format("{0} {1} {2} {3} {4} {5} {6}", a, b, c, d, e, f, g);
_pySkript.UseShellExecute = false;
_pySkript.RedirectStandardOutput = true;
_pySkript.CreateNoWindow = true;
_pySkript.RedirectStandardError = true;
_pySkript.RedirectStandardInput = true;
_pySkript.ErrorDialog = false;
_pySkript.WindowStyle = ProcessWindowStyle.Hidden;
using (Process process = Process.Start(_pySkript))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
OnScriptRunFinished();
return result;
}
}
}
感谢@BugFinder的支持。最后是拼写错误
示例解决方案:
第一个项目:Logic.csproj
第二个项目:ScriptRunner.csproj
第三个项目:ScriptRunnerService.csproj
安装服务:
您需要InstallUtil.exe来安装服务
installutil-i ScriptRunnerService.exe
Windows键:r 服务.msc->;启动服务 eventvwr.msc->;检查日志
卸载服务:
installutil-u ScriptRunnerService.exe
在GitHub
相关问题 更多 >
编程相关推荐