本文整理汇总了Python中WhfLog.debug_ncl方法的典型用法代码示例。如果您正苦于以下问题:Python WhfLog.debug_ncl方法的具体用法?Python WhfLog.debug_ncl怎么用?Python WhfLog.debug_ncl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WhfLog
的用法示例。
在下文中一共展示了WhfLog.debug_ncl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import WhfLog [as 别名]
# 或者: from WhfLog import debug_ncl [as 别名]
def run(cmd):
"""
Execute the external command and get its exitcode, stdout and stderr.
Parameters
----------
cmd : str
The NCL command
Returns
-------
int: exitcode
"""
# log the command prior to doing anything
WhfLog.debug_ncl(cmd)
# do the command in a way where stdout and stderr can be grabbed as strings
args = shlex.split(cmd)
proc = Popen(args, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
exitcode = proc.returncode
if err:
# get rid of annoying error about not making directory that exists
header = 'mkdir: cannot create directory'
tail = 'File exists'
ltail = len(tail)
i = err.find(header)
if (i >= 0):
j = err.find(tail)
if (j > i):
err = err[0:i] + err[j+ltail:]
k = err.find('\n')
if (k ==0):
if (len(err) > 1):
# multi line error, not just this annoying one
err = err[1:]
else:
# just the annoying line
err = ""
if (err):
# Log errors PRIOR to logging output
WhfLog.error_ncl(err)
if out:
# Go ahead and log the output, which is usually some big multiline string
WhfLog.debug_ncl(out)
# return the exit code, for those who want to know
return exitcode