欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

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

时间:2020-11-26 22:20:37|栏目:Python代码|点击:

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函数修饰符@的使用方法解析

栏    目:Python代码

下一篇:Django 接收Post请求数据,并保存到数据库的实现方法

本文标题:python调用staf自动化框架的方法

本文地址:http://www.codeinn.net/misctech/26487.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有