当前位置: 移动技术网 > IT编程>脚本编程>Python > python调用staf自动化框架的方法

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

2019年01月07日  | 移动技术网IT编程  | 我要评论

老河口社区,狄仁杰第二部演员表,2013年国考行测真题

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()

参考文档:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网