python调用staf自动化框架的方法
程序员文章站
2022-06-16 20:37:22
1、配置环境
支持python2和python3
on linux, solaris, or freebsd, add the /usr/local/staf/lib...
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
以上这篇python调用staf自动化框架的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。