作为Windows服务运行的Python:OSError:[WinError 6]句柄无效
发布时间:2020-12-13 20:31:59 所属栏目:Windows 来源:网络整理
导读:我有一个Python脚本,它作为Windows服务运行.该脚本分叉另一个进程: with subprocess.Popen( args=[self.exec_path],stdout=subprocess.PIPE,stderr=subprocess.STDOUT) as proc: 这会导致以下错误: OSError: [WinError 6] The handle is invalid File "C:
我有一个Python脚本,它作为Windows服务运行.该脚本分叉另一个进程:
with subprocess.Popen( args=[self.exec_path],stdout=subprocess.PIPE,stderr=subprocess.STDOUT) as proc: 这会导致以下错误: OSError: [WinError 6] The handle is invalid File "C:Program Files (x86)Python35-32libsubprocess.py",line 911,in __init__ File "C:Program Files (x86)Python35-32libsubprocess.py",line 1117,in _get_handles
subprocess.py中的第1117行是:
p2cread = _winapi.GetStdHandle(_winapi.STD_INPUT_HANDLE) 这让我怀疑服务流程没有与之关联的STDIN(TBC) 通过向popen提供文件或空设备作为stdin参数,可以避免这种麻烦的代码. 在Python 3.x中,您可以简单地传递stdin = subprocess.DEVNULL.例如. subprocess.Popen( args=[self.exec_path],stderr=subprocess.STDOUT,stdin=subprocess.DEVNULL) 在Python 2.x中,您需要将文件处理程序设置为null,然后将其传递给popen: devnull = open(os.devnull,'wb') subprocess.Popen( args=[self.exec_path],stdin=devnull) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – 如何从第x行到第y行读取文件(dos / win批处理文
- .NET Windows Forms自定义控件,如何创建快捷菜单
- windows – 如何使用批处理脚本对目录中的每个文件执行多项
- group-policy – 通过GPO或PowerShell部署二进制十六进制注
- 用于Microsoft Office文件的Android API或库[已关闭]
- 域名系统 – 在Windows上启用不安全的DNS更新有哪些实际风险
- 【windows】windows server 系统管理的快捷命令
- windows-server-2008-r2 – Windows Server 2008R2中的DHCP
- windows-server-2008 – 在ISAPI筛选器上调用LoadLibraryEx
- windows-server-2012 – 在RDP会话中禁用Metro:Windows Se