Page 1 of 1

ASCIIOUTPUT file locking/unlocking

Posted: Thu Dec 05, 2013 4:23 am
by fleaster
Hi all,
as you are probably aware, when calling an ASCIIOUTPUT function, TM1 will open the file for writing during the duration of the Prolog/Meta/Data/Epilog tab, then close it when proceeding to the next tab or exiting the process.

Question: Is there any way to force TM1 to close the file without needing to move to the next tab or exit the process?

...the context is I am creating a set of files that requires header+detail+footer sections. The header/details are written during the Data tab, and the footer files are written during the Epilog tab.

The next step is to merge all the detail+footer files together - however I have found I cannot do this during the Epilog tab of the original process (presumably because the footer files are still open) - hence I would need to create a whole new process just to merge the files.
Note: calling another process (to executecommand) from the Epilog also didnt seem to work - it appears that you have to exit the Epilog of the original process entirely.

Anyway, if anyone has any tips or workarounds for this it would be much appreciated.. otherwise I'll just have to go the long way around :p

Cheers,

Matt

Re: ASCIIOUTPUT file locking/unlocking

Posted: Thu Dec 05, 2013 5:05 am
by rmackenzie
Are you aware of the command line operators that allow you to write/ append to file?

Usage in TI per this example:

Code: Select all

# setup
sFile = 'd:\data\temp.txt';

# test prolog output
sOutput = 'red lorry';
sCommand = 'cmd /c "echo ' | sOutput | ' >> ' | sFile | '"';
ExecuteCommand ( sCommand, 0 );

# ... skip to Epilog now
# test epilog output
sOutput = 'yellow lorry';
sCommand = 'cmd /c "echo ' | sOutput | ' >> ' | sFile | '"';
ExecuteCommand ( sCommand, 0 );
I've spread the examples over 3 lines for readability but you could squeeze them into one-liners to replace your AsciiOutputs. Then, you won't need to worry about how TI obtains and releases the file handles, or worry about the file-merging logic.

Re: ASCIIOUTPUT file locking/unlocking

Posted: Thu Dec 05, 2013 12:34 pm
by fleaster
thanks for the tip :)

fyi in the end I used this in conjunction with the echo command to write directly to the file (saves creating a separate file) e.g. something like :

Code: Select all

echo   this-is-my-footer  >>  "datafile.txt"

Re: ASCIIOUTPUT file locking/unlocking

Posted: Thu Dec 05, 2013 2:31 pm
by BariAbdul
fleaster wrote:thanks for the tip :)

fyi in the end I used this in conjunction with the echo command to write directly to the file (saves creating a separate file) e.g. something like :

Code: Select all

echo   this-is-my-footer  >>  "datafile.txt"
fleaster,Could you please post your complete code.Thanks

Re: ASCIIOUTPUT file locking/unlocking

Posted: Thu Dec 05, 2013 10:17 pm
by fleaster
Hi BariAbdul,

Please see below:

Code: Select all

    # execute command to append footer string to end of each output file    
    # e.g.    cmd /c echo 97020130920000.....  >> "\\TM1\DataUser\Working\ProofOutput-70.txt"

    CommandAppend = 'cmd /c echo ' | FooterString | ' >> ' | '"' | AppendPath | '"' ;

    ExecuteCommand(CommandAppend,1);
...where FooterString is the line of text being appended for the footer, and AppendPath is the destination txt file being updated.

Re: ASCIIOUTPUT file locking/unlocking

Posted: Fri Dec 06, 2013 4:17 am
by BariAbdul
Thanks a lot.