网络编程
位置:首页>> 网络编程>> Python编程>> python调用staf自动化框架的方法

python调用staf自动化框架的方法

作者:hqzxsc2006  发布时间:2021-11-03 17:47:43 

标签:python,staf,框架

1、配置环境

支持python2和python3

On Linux, Solaris, or FreeBSD, add the /usr/local/staf/lib directory to your PYTHONPATH, assuming you installed STAF to directory /usr/local/staf. For example:

export PYTHONPATH=/usr/local/staf/lib:$PYTHONPATH

On Mac OS X, add the /Library/staf/lib directory to your PYTHONPATH, assuming you installed STAF to directory /Library/staf. For example:

On Windows, add the C:\STAF\bin directory to your PYTHONPATH, assuming you installed STAF to directory C:\STAF. For example:

set PYTHONPATH=C:\STAF\bin;%PYTHONPATH%

2、python代码


from PySTAF import STAFHandle
from PySTAF import STAFException
import sys

try:
 handle = STAFHandle("MyTest")
except STAFException, e:
 print "Error registering with STAF, RC: %d" % e.rc
 sys.exit(e.rc)

#判断本地staf服务是否正常,结果是PONG代表服务正常
result = handle.submit("local", "ping", "ping")
if (result.rc != 0):
 print "Error submitting request, RC: %d, Result: %s" % (result.rc, result.result)

result = handle.submit("local", "var", "resolve string {STAF/Config/OS/Name}")
if (result.rc != 0):
 print "Error submitting request, RC: %d, Result: %s" % (result.rc, result.result)
else:
 print "OS Name: %s" % result.result
#执行命令,要执行远程,把local替换远程ip,如打开notepad
result = handle.submit("local", "PROCESS", "start command notepad")
print "Error submitting request, RC: %d, Result: %s" % (result.rc, result.result)
#执行完记得注销handle
rc = handle.unregister()

参考文档:http://staf.sourceforge.net/current/STAFPython.htm

来源:https://blog.csdn.net/hqzxsc2006/article/details/81289452

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com