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

作者:hqzxsc2006 时间:2021-11-03 17:47:43 

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

来源:https://blog.csdn.net/hqzxsc2006/article/details/81289452

标签:python,staf,框架
0
投稿

猜你喜欢

  • 一文带你深入了解Python中的二次移动平均法

    2021-08-30 00:28:12
  • Ceph集群CephFS文件存储核心概念及部署使用详解

    2023-04-18 02:23:31
  • 关于设计的一些个人看法

    2008-06-12 12:44:00
  • python切片的步进、添加、连接简单操作示例

    2022-09-10 01:26:34
  • 修改apache配置文件去除thinkphp url中的index.php

    2024-05-21 10:21:10
  • python 获取微信好友列表的方法(微信web)

    2022-02-20 10:05:21
  • 网页中常用数字/字母序号与代码对照表

    2009-03-19 14:00:00
  • 分析python切片原理和方法

    2021-04-19 21:39:03
  • SQL Server TEXT、NTEXT字段拆分的问题

    2008-10-26 12:28:00
  • MySQL深分页问题解决的实战记录

    2024-01-18 21:32:36
  • Python基于贪心算法解决背包问题示例

    2022-10-31 01:25:56
  • SQL学习笔记八 索引,表连接,子查询,ROW_NUMBER

    2024-01-14 02:36:14
  • Python脚本修改阿里云的访问控制列表的方法

    2022-06-19 10:31:18
  • Python实现文件操作帮助类的示例代码

    2023-02-14 16:46:57
  • Sql server2005 优化查询速度50个方法小结

    2024-01-26 16:51:52
  • 浅析JavaScript中的array数组类型系统

    2024-04-17 10:04:21
  • sqlserver主键设计的注意点

    2012-08-21 10:42:44
  • Python Socket编程详细介绍

    2021-01-02 02:56:21
  • Python微信库:itchat的用法详解

    2022-02-17 10:54:33
  • Python数据分析之 Matplotlib 折线图绘制

    2023-12-05 02:18:13
  • asp之家 网络编程 m.aspxhome.com