Execute a temporary batch file
- Feb. 14, 2010
|Example files with this article:|
TI allows you to execute batch files that reside on the TM1 server or any other location that can be accessed. This is the purpose of the EXECUTECOMMAND function. The file could be static (in which case it is executed as is), but one can make it more dynamic by first generating a batch file with custom contents, then execute the batch file and delete it again. Here′s how you can do this:
A TI process
Create a new process. Choose None as Datasource Type.
Here is the code in the Prolog tab:
# Wim Gielis # http://www.wimgielis.com# 0. preliminary vTempFileName='C:\BV\username.bat'; DatasourceASCIIQuoteCharacter=''; # 1. create the temporary bat file ASCIIOUTPUT(vTempFileName,'cd "C:\TM1"'); ASCIIOUTPUT(vTempFileName,'echo %username% >> usernames.txt');
Here is the code in the Epilog tab:
# 2. execute the file EXECUTECOMMAND(vTempFileName,1); # 3. kill the temporary bat file again ASCIIDELETE(vTempFileName);
To gain time, right-click the file above and Save it. Pretty straightforward code I would say. The process creates the file usernames.bat in the folder C:\BV. After that, it executes the bat file and kills it again. As a result, the username in Windows is appended to the file C:\TM1\usernames.txt.
Things become really interesting if your process contains a data source that you process in the metadata/data tabs. Over there, you can add lines to a text file with ASCIIOUTPUT, as we demonstrated above.
File handling systems
A nice example of this technique, could be a file handling system. Each night, input files are to be picked up by a TI chore. After processing in TM1, we can output the status to a text file: we could automatically move successfully processed input files to a folder called Success, and unsuccessfully processed input files to a folder called Failure. Only this folder should be monitored by TM1 Admin users. Make sure that the user who executes the file move operations should have sufficient rights to do so.