当前位置: 首页>>代码示例>>Python>>正文


Python Process.getInputStream方法代码示例

本文整理汇总了Python中Process.Process.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Python Process.getInputStream方法的具体用法?Python Process.getInputStream怎么用?Python Process.getInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Process.Process的用法示例。


在下文中一共展示了Process.getInputStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: runExternalFilter

# 需要导入模块: from Process import Process [as 别名]
# 或者: from Process.Process import getInputStream [as 别名]
	def runExternalFilter(self, inputStream, outputStream):
		if self.__use_stdin:
			inFile = None
		else:
			inFile = self.newTempFile("%s.in" % self.__class__.__name__)
			Pump.stream2file(inputStream, inFile)

		if self.__use_stdout:
			outFile = None
		else:
			outFile = self.newTempFile("%s.out" % self.__class__.__name__)

		cmd = self.getCommandLine(inFile, outFile)

		try:
			assert trace("Starting %s: %s" % (self.__name, cmd))
			xfilter = Process(cmd, separate_stderr=self.__separate_stderr)
			if self.__use_stdin:
				assert trace("Writing file to %s stdin" % self.__name)
				Pump.stream2stream(inputStream, xfilter.getInputStream())
			
			if self.__use_stdout:
				# output 
				assert trace("Pumping %s stdout to outputStream" % self.__name)
				Pump.stream2stream(xfilter.getOutputStream(), outputStream)

				if self.__separate_stderr:
					assert trace("Handling %s stderr" % self.__name)
					self.handleErrorOutput(xfilter.getErrorStream())
			else:
				assert trace("Handling %s stdout" % self.__name)
				self.handleOutput(xfilter.getOutputStream())

				if self.__separate_stderr:
					assert trace("Handling %s stderr" % self.__name)
					self.handleErrorOutput(xfilter.getErrorStream())

			rc = xfilter.waitFor()
			assert trace("%s finished with exit code: 0x%X" % (self.__name, rc))
			if not (rc in self.__normalReturnCodes):
				raise ExternalFilterException, "Return code 0x%X" % (rc,)

			if not self.__use_stdout:
				if os.path.exists(outFile):
					try:
						if os.path.getsize(outFile) > 0:
							Pump.file2stream(outFile, outputStream, "b")
						else:
							raise ExternalFilterException, "Output file is empty: %s" % (outFile,)
					finally:
						self.removeTempFile(outFile)
				else:
					raise ExternalFilterException, "Output file not found: %s" % (outFile,)

		finally:
			if inFile is not None:
				self.removeTempFile(inFile)
				pass

		return rc
开发者ID:HarmonyEnterpriseSolutions,项目名称:toolib,代码行数:62,代码来源:ExternalFilter.py


注:本文中的Process.Process.getInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。