您好,登錄后才能下訂單哦!
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自動化框架的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。