服务器之家

服务器之家 > 正文

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

时间:2021-05-08 00:20     来源/作者:hqzxsc2006

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代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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

以上这篇python调用staf自动化框架的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/hqzxsc2006/article/details/81289452

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
返回顶部