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

yipeiwu_com6年前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调用staf自动化框架的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python 使用matplotlib模块模拟掷骰子

Python 使用matplotlib模块模拟掷骰子

掷骰子 骰子类 # die.py 骰子类模块 from random import randint class Die(): """骰子类""" def __init__(s...

SublimeText 2编译python出错的解决方法(The system cannot find the file specified)

[Error 2] The system cannot find the file specified 解决方法:1.环境变量path添加:C:\Python32\Tools\Scrip...

python可视化实现代码

python可视化实现代码

python可视化 #导入两个库 import numpy as np import matplotlib.pyplot as plt #第一个参数就是x轴的初始值 #第二个参数是...

基于python使用tibco ems代码实例

 这篇文章主要介绍了基于python使用tibco ems代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 TIBCO...

Python对List中的元素排序的方法

首先定义一个compare函数: def compare(sf1, sf2): if (sf1.value > sf2.value): return -1; e...