This month's Task Of The Month compliments our Tech Tech article by providing an example of executing a command-line application using the Run action that directs its output and return code to two different files. These files are then read into Automate variables for display and analysis.

<AMVARIABLE NAME="DirectoryContents" DESCRIPTION="Stores the contents of the directory"></AMVARIABLE>
<AMVARIABLE NAME="CommandLineResultCode" DESCRIPTION="The result code of our command line"></AMVARIABLE>

<!--- Run our command line that outputs the directory to a file called "DirListing.txt" and the error code to "ResultCode.txt". These will be written into the Temp directory (as defined by the system). Note we haev to double up the percentages around ERRORLEVEL to escape them. Otherwise Automate will think we are referring to an Automate variable called Errorlevel. --->

<AMRUN FILE="cmd.exe /C dir C:\ &gt; %TEMP%\DirListing.txt &amp;&amp; echo %%ERRORLEVEL%% &gt; %TEMP%\ResultCode.txt&quot;" WAITFORINPUT="NO" WAITFOREND="YES">
<!--- Read the results into our variables --->
<AMFILEREAD FILE="%TEMP%\DirListing.txt" RESULTVARIABLE="DirectoryContents">
<AMFILEREAD FILE="%TEMP%\ResultCode.txt" RESULTVARIABLE="CommandLineResultCode">
<!--- Clean up our files... --->
<!--- Display the result --->
<AMMESSAGEBOX>Directory contents are:

Result code for the command was:

<AMIF EXPRESSION="%CommandLineResultCode% = 0">
<AMMESSAGEBOX>The command-line executed successfully.</AMMESSAGEBOX>
<AMMESSAGEBOX>The command-line failed with return code %CommandLineResultCode%.</AMMESSAGEBOX>

Applies to: Automate 10

Still have questions? We can help. Submit a case to Technical Support.

Last Modified On: October 30, 2019