Hi,
I'll try to make myself clearer.
I have a command that runs something like 10 minutes, and I want to get the command status in live, I mean , for example , I want to ping from one machine to another for 10 minutes, but I want staf to show the command output , as long as there is one ofcourse, and not to wait to the command to end to determine its status.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
STAF doesn't provide a direct way to get the content of a process's stdout/stderr while the process is running. It doesn't provide the ability to return the process's stdout/stderr until the process completes. However, you could specify the name of the stdout/stderr file when starting the process using the STDOUT option. Then, while the process is running, you could access this file by submitting a STAF FS GET FILE request, or submit a PROCESS START request that runs a command like tail or cat to get the contents of the stdout file name you specified.
Can you provide examples of these 2 options for capturing the stdout in the STAX screen? I've been trying various permutations without much luck. Thank you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here's an example of a STAX job that can use either:
- a FS GET FILE request to get the entire contents of the process's stdout file
or
- a 'tail -n10' command to get the last 10 lines of the process's stdout file
and display the stdout data in the "Messages" panel of the STAX Monitor (and log it to the STAX Job User's log file).
<?xmlversion="1.0"encoding="UTF-8"standalone="no"?><!DOCTYPEstaxSYSTEM"stax.dtd"><stax><defaultcallfunction="Main"/><functionname="Main"><sequence><script># Set to either 'FS' or 'tail'.# 'FS' indicates to get the entire contents of the stdout file# using a FS GET FILE request, or# 'tail' indicates to get the last 10 lines of the stdout file# using the tail command.getMethod='FS'pingMachine='staf1e'#SettothehostnameoranIPaddressof# a system in your network</script><!--Thisexampleisrunningaprocessthatnevercompletes,acontinuouspingcommandsoneedatimertostopitafter1minute.Insteadofusingacontinuepingcommand(justbecauesitcontinuouslygeneratesoutput)todemonstrateretrievingprocessoutputwhiletheprocessisstillrunning,youwouldsetthecommandvaluewithwhateveryourrealcommandisandprobablyremovethetimerelementenclosingthecalltotheRunProcessfunction.--><timerduration="'1m'"><callfunction="'RunProcess'">{'machine':'local','command':'ping-t%s'%(pingMachine),'stdoutFileName':'C:/temp/process.out'}</call></timer></sequence></function><functionname="RunProcess"><function-map-args><function-required-argname="machine">Machinewheretheprocesswillberun</function-required-arg><function-required-argname="command">Thecommandtoberunonthespecifiedmachineviatheprocesselement</function-required-arg><function-optional-argname="stdoutFileName"default="'/tmp/process.out'">Thenameofthefileonthespecifiedmachinewheretheprocess'sstdout/stderrdatawillbewritten</function-optional-arg></function-map-args><sequence><processname="command"><location>machine</location><commandmode="'shell'">command</command><stdout>stdoutFileName</stdout><stderrmode="'stdout'"/><returnstdout/><!--Usesaprocess-actionsub-elementtorunataskinparallelwhiletheprocessisrunningtoretrievedatafromtheprocess'sstdout/stderrfile--><process-action><callfunction="'GetProcessOutput'">{'machine':machine,'stdoutFileName':stdoutFileName,'getMethod':getMethod,'delayTime':'10s'}</call></process-action></process><script>processRC=RC# Get the process's complete stdout/stderr from the STAXResultifSTAXResult!=None:processStdout=STAXResult[0][1]else:processStdout=None</script><ifexpr="RC != 0"><logmessage="1"level="'error'">"""Process failed. RC=%d, STAFResult=%s, Stdout:%s""" % (processRC, STAFResult, processStdout)</log><else><logmessage="1">"""Process completed successfully (RC=0) Stdout:%s""" % (processStdout)</log></else></if><return>processRC</return></sequence></function><functionname="GetProcessOutput"><function-map-args><function-required-argname="machine">Machinewheretheprocesswillberun</function-required-arg><function-required-argname="stdoutFileName">Thenameofthefileonthespecifiedmachinewheretheprocess'sstdout/stderrdatawillbewritten</function-required-arg><function-optional-argname="getMethod"default="'FS'">Specifieswhethertogetthelast10linesofdataintheprocess'sstdoutfileortosubmitaGETFILErequesttotheFSservicetogettheentirecontentsoftheprocessstdoutfile.Validvaluesare'tail'or'FS'anditdefaultsto'FS'.Note:Tousetail,thiscommandmustbeavailableonthesystemwheretheprocessisrunning.UnixsystemsprovidethetailcommandandonWindowsifyouhaveCygwininstalledandinthePATHyoucanusethetailcommand.</function-optional-arg><function-optional-argname="delayTime"default="'10s'">Timetowaitduringaloopbeforegettingtheprocess'sstdout/stderre.g.10s,30s,1m,30m,1h,1d,dtc</function-optional-arg></function-map-args><blockname="'GetProcessOutput'"><sequence><!--Whiletheprocessisstillrunning,inaloopthatcontinuesuntiltheprocesshascompleted,waitforthespecifieddelayTimeandthenretrievethelastxxlinesofoutputwrittentotheprocess'sstdout/stderrfile.Todetermineiftheprocessisstillrunning,itsubmitsaPROCESSQUERYHANDLEreuqestspecifyingSTAXProcessHandlewhichcontainsthehandleoftheprocessandifitfails,itassumestheprocessisnolongerrunning.--><script>processComplete=0delayTime='10s'#Youcansetthistohowlongyouwanttowait# before getting the process's stdout/stderr# e.g. 10s, 30s, 1m, 30m, 1h, 1d, etcifgetMethod=='tail':numLines=10#Youcanconfiguretothenumberoflinesinthe# process's stdout file that you want the tail# command to return.command='tail-n%s%s'%(numLines,stdoutFileName)else:request='GETFILE%sTEXT'%(stdoutFileName)msg=''</script><loopuntil="processComplete"><sequence><stafcmdname="'Delay %s' % (delayTime)"><location>'local'</location><service>'DELAY'</service><request>'DELAY%s'%(delayTime)</request></stafcmd><ifexpr="getMethod == 'tail'"><sequence><!--Usetailtogetthelast10linesinthestdoutfile--><processname="command"><location>machine</location><command>command</command><stderrmode="'stdout'"/><returnstdout/></process><script>ifRC==0:ifSTAXResult!=None:msg=STAXResult[0][1]else:msg=Noneelse:msg='Command"%s"failedwithRC=%sSTAFResult=%sSTAXResult=%s'% \
(command,RC,STAFResult,STAXResult)</script></sequence><else><sequence><!--SubmitaFSGETFILEcommandtogetthecontentsofthestdoutfile--><stafcmdname="request"><location>machine</location><service>'FS'</service><request>request</request></stafcmd><script>ifRC==0:msg=STAFResultelse:msg='STAF%sFS%sfailedwithRC=%sResult=%s'% \
(machine,request,RC,STAFResult)</script></sequence></else></if><logmessage="1">msg</log><!--Nowcheckiftheprocessisstillrunning--><stafcmd><location>machine</location><service>'PROCESS'</service><request>'QUERYHANDLE%s'%(STAXProcessHandle)</request></stafcmd><ifexpr="RC != 0"><sequence><logmessage="1">'STAF%sPROCESSQUERYHANDLE%sfailedwithRC=%sResult=%s'% \
(RC,STAFResult)</log><script>processComplete=1</script></sequence></if></sequence></loop></sequence></block></function></stax>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'll try to make myself clearer.
I have a command that runs something like 10 minutes, and I want to get the command status in live, I mean , for example , I want to ping from one machine to another for 10 minutes, but I want staf to show the command output , as long as there is one ofcourse, and not to wait to the command to end to determine its status.
Thanks
STAF doesn't provide a direct way to get the content of a process's stdout/stderr while the process is running. It doesn't provide the ability to return the process's stdout/stderr until the process completes. However, you could specify the name of the stdout/stderr file when starting the process using the STDOUT option. Then, while the process is running, you could access this file by submitting a STAF FS GET FILE request, or submit a PROCESS START request that runs a command like tail or cat to get the contents of the stdout file name you specified.
We also have a feature request open that would enable this to be done in another way (but it is not implemented yet). For more information see Feature #523877 "Add open/read/write/close support to FS" at http://sourceforge.net/tracker/?func=detail&aid=523877&group_id=33142&atid=407384.
Can you provide examples of these 2 options for capturing the stdout in the STAX screen? I've been trying various permutations without much luck. Thank you.
Here's an example of a STAX job that can use either:
- a FS GET FILE request to get the entire contents of the process's stdout file
or
- a 'tail -n10' command to get the last 10 lines of the process's stdout file
and display the stdout data in the "Messages" panel of the STAX Monitor (and log it to the STAX Job User's log file).