|
|
@ -24,10 +24,20 @@ def OSFileTextDataStrCreate(inFilePathStr, inFileDataStr, inEncodingStr = "utf-8
|
|
|
|
A2O.LogListSend(inGSettings=inGSettings, inLogList=[lMessageStr])
|
|
|
|
A2O.LogListSend(inGSettings=inGSettings, inLogList=[lMessageStr])
|
|
|
|
|
|
|
|
|
|
|
|
# Send CMD to OS. Result return to log + Orchestrator by the A2O connection
|
|
|
|
# Send CMD to OS. Result return to log + Orchestrator by the A2O connection
|
|
|
|
def OSCMD(inCMDStr, inRunAsyncBool=True, inGSettings = None):
|
|
|
|
def OSCMD(inCMDStr, inRunAsyncBool=True, inGSettings = None, inSendOutputToOrchestratorLogsBool = True, inCMDEncodingStr = "cp1251"):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Execute CMD on the Agent daemonic process
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:param inCMDStr: command to execute on the Agent session
|
|
|
|
|
|
|
|
:param inRunAsyncBool: True - Agent processor don't wait execution; False - Agent processor wait cmd execution
|
|
|
|
|
|
|
|
:param inGSettings: Agent global settings dict
|
|
|
|
|
|
|
|
:param inSendOutputToOrchestratorLogsBool: True - catch cmd execution output and send it to the Orchestrator logs; Flase - else case; Default True
|
|
|
|
|
|
|
|
:param inCMDEncodingStr: Set the encoding of the DOS window on the Agent server session. Windows is beautiful :) . Default is "cp1251" early was "cp866" - need test
|
|
|
|
|
|
|
|
:return:
|
|
|
|
|
|
|
|
"""
|
|
|
|
lResultStr = ""
|
|
|
|
lResultStr = ""
|
|
|
|
# Subdef to listen OS result
|
|
|
|
# Subdef to listen OS result
|
|
|
|
def _CMDRunAndListenLogs(inCMDStr, inGSettings = None):
|
|
|
|
def _CMDRunAndListenLogs(inCMDStr, inSendOutputToOrchestratorLogsBool, inCMDEncodingStr, inGSettings = None):
|
|
|
|
lL = inGSettings.get("Logger",None) if type(inGSettings) is dict else None
|
|
|
|
lL = inGSettings.get("Logger",None) if type(inGSettings) is dict else None
|
|
|
|
lResultStr = ""
|
|
|
|
lResultStr = ""
|
|
|
|
lOSCMDKeyStr = str(uuid.uuid4())[0:4].upper()
|
|
|
|
lOSCMDKeyStr = str(uuid.uuid4())[0:4].upper()
|
|
|
@ -43,11 +53,11 @@ def OSCMD(inCMDStr, inRunAsyncBool=True, inGSettings = None):
|
|
|
|
lOutputLineBytes = lCMDProcess.stdout.readline()
|
|
|
|
lOutputLineBytes = lCMDProcess.stdout.readline()
|
|
|
|
if lOutputLineBytes == b"":
|
|
|
|
if lOutputLineBytes == b"":
|
|
|
|
lListenBool = False
|
|
|
|
lListenBool = False
|
|
|
|
lStr = lOutputLineBytes.decode('cp866')
|
|
|
|
lStr = lOutputLineBytes.decode(inCMDEncodingStr) # was cp866, on win server don't work properly - set cp1251
|
|
|
|
if lStr.endswith("\n"): lStr = lStr[:-1]
|
|
|
|
if lStr.endswith("\n"): lStr = lStr[:-1]
|
|
|
|
lMessageStr = f"{lOSCMDKeyStr}: {lStr}"
|
|
|
|
lMessageStr = f"{lOSCMDKeyStr}: {lStr}"
|
|
|
|
if lL: lL.info(lMessageStr)
|
|
|
|
if lL: lL.info(lMessageStr)
|
|
|
|
A2O.LogListSend(inGSettings=inGSettings, inLogList=[lMessageStr])
|
|
|
|
if inSendOutputToOrchestratorLogsBool: A2O.LogListSend(inGSettings=inGSettings, inLogList=[lMessageStr])
|
|
|
|
lResultStr+=lStr
|
|
|
|
lResultStr+=lStr
|
|
|
|
lMessageStr = f"{lOSCMDKeyStr}: # # # # AGENT CMD Process has been FINISHED # # # # "
|
|
|
|
lMessageStr = f"{lOSCMDKeyStr}: # # # # AGENT CMD Process has been FINISHED # # # # "
|
|
|
|
if lL: lL.info(lMessageStr)
|
|
|
|
if lL: lL.info(lMessageStr)
|
|
|
@ -55,11 +65,11 @@ def OSCMD(inCMDStr, inRunAsyncBool=True, inGSettings = None):
|
|
|
|
return lResultStr
|
|
|
|
return lResultStr
|
|
|
|
# New call
|
|
|
|
# New call
|
|
|
|
if inRunAsyncBool:
|
|
|
|
if inRunAsyncBool:
|
|
|
|
lThread = threading.Thread(target=_CMDRunAndListenLogs, kwargs={"inCMDStr":inCMDStr, "inGSettings":inGSettings})
|
|
|
|
lThread = threading.Thread(target=_CMDRunAndListenLogs, kwargs={"inCMDStr":inCMDStr, "inGSettings":inGSettings, "inSendOutputToOrchestratorLogsBool":inSendOutputToOrchestratorLogsBool, "inCMDEncodingStr":inCMDEncodingStr })
|
|
|
|
lThread.start()
|
|
|
|
lThread.start()
|
|
|
|
lResultStr="ActivityList has been started in async mode - no output is available here."
|
|
|
|
lResultStr="ActivityList has been started in async mode - no output is available here."
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
lResultStr = _CMDRunAndListenLogs(inCMDStr=inCMDStr, inGSettings=inGSettings)
|
|
|
|
lResultStr = _CMDRunAndListenLogs(inCMDStr=inCMDStr, inGSettings=inGSettings, inSendOutputToOrchestratorLogsBool = inSendOutputToOrchestratorLogsBool, inCMDEncodingStr = inCMDEncodingStr)
|
|
|
|
#lCMDCode = "cmd /c " + inCMDStr
|
|
|
|
#lCMDCode = "cmd /c " + inCMDStr
|
|
|
|
#subprocess.Popen(lCMDCode)
|
|
|
|
#subprocess.Popen(lCMDCode)
|
|
|
|
#lResultCMDRun = 1 # os.system(lCMDCode)
|
|
|
|
#lResultCMDRun = 1 # os.system(lCMDCode)
|
|
|
|