Recently I wrote some batch files to complement some scheduled tasks I was developing to help with automating some processes that were being carried out manually by system administrators on applications deployed in a Microsoft Windows environment.
In doing so I came across a number of minor issues that I had to figure out, so I thought I'd share them here for anyone else who's ever required to do anything similar.
I was calling the batch file using the <cfexecute /> tag and passing some arguments to keep the script cohesive enough that its functionality could be used on other servers.
The code final code I used is below but I have discussed the important parts that I had left out.
<cftry> <cfscript> args = ; args = "argument1Value"; args = "argument2Value"; args = "argument3Value"; </cfscript> <cfexecute variable="batchScriptOutput" name="#APPLICATION.BATCH_SCRIPT_DIRECTORY#\#APPLICATION.NAME_OF_SCRIPT#" arguments="#args#" timeout="99999" errorVariable="batchScriptError" /> <cfoutput> SCRIPT OUTPUT:<br />#batchScriptOutput#<br /> ERRORS:<br />#batchScriptError#<br /> </cfoutput> <cfcatch> <cfrethrow /> </cfcatch> </cftry>
The issues I had were that:
- I wanted to pass argument values that had spaces in them
- I wanted to see the output generated by the batch file
Neither of this seemed possible without formatting the code as I have above. If a "timeout" value wasn't set, I didn't get the output returned and it just seemed simpler to pass the arguments as an array.
If anyone has had any similar experiences or better methods of implementation, I would like to hear your thoughts.