Page 1 of 1
Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 12:07 am
by TM1New
Dear members,
i am trying to move the import files into archive location after the successful data load in TI process.
Below is the script i am using to archive the file, but unable to do that, when i run the same script through command prompt, i can do that.
Code: Select all
sScript = 'move /y ' ;
sImportdir = 'D:\TM1Model\Import\Test.txt ' ;
sArchivedir = 'D:\TM1Model\Archive\' ;
sCommand = sScript | sImportdir | sArchivedir ;
EXECUTECOMMAND( sCommand , 0 ) ;
Can you please help me to fix this.
Cheers
Re: Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 12:23 am
by Alan Kirk
TM1New wrote:
i am trying to move the import files into archive location after the successful data load in TI process.
Below is the script i am using to archive the file, but unable to do that, when i run the same script through command prompt, i can do that.
Code: Select all
sScript = 'move /y ' ;
sImportdir = 'D:\TM1Model\Import\Test.txt ' ;
sArchivedir = 'D:\TM1Model\Archive\' ;
sCommand = sScript | sImportdir | sArchivedir ;
EXECUTECOMMAND( sCommand , 0 ) ;
Can you please help me to fix this.
Two things to consider:
(a) When you say "when i run the same script through command prompt, i can do that",
where are you doing that? Because if it's not on the server itself, then you need to ensure that the folders that you have specified are ones that account that the TM1 server is running under has access to.
(b) Where are you running the ExecuteCommand statement from? If it's the Epilog of the process that is using the file as a data source then the process may (probably will) still have a lock on the file and it won't delete. I tend to do such cleanups in a later process in the chore.
Re: Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 12:30 am
by EvgenyT
Hello,
CMD command requires double quotes around path ("path"), hence why it cannot interpret you script
Save you script in notepad and save it as .bat file (file content: move/y "D:\TM1Model\Import\Test.txt" "D:\TM1Model\Archive\"), and run it via ExecuteCommand, i.e
sCommand = 'Location of the file.bat';
EXECUTECOMMAND( sCommand , 0 ) ;
Of course after your considered Allan's suggestions
Thanks
ET
Re: Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 12:31 am
by TM1New
Hi Alan,
Thanks for your prompt response on this.
I have taken asciioutput of the SCommand and execute this in the server through command prompt. it works fine.
But when i execute the script from the Epilog tab of the process, it's throwing error saying "System can't find the file specified" error.
Cheers
Re: Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 12:33 am
by TM1New
Hi Evgeny,
The problem is i have to loop through all the files in the path and then Archive them after the load ( file names will change ).
If i create this as a batch file, then i can't pass the parameters?
Cheers
Re: Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 12:39 am
by EvgenyT
Hi There,
So, what are you telling me is that you want to archive all the files in the folder?
ET
Re: Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 12:46 am
by TM1New
There are total 10 files in the import folder, i have to pick all the files and load them using one TI process.
I don't want to create multiple TI's for this job and i am planning to create one TI which will loop through all files and perform data load.
Cheers
Re: Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 1:06 am
by Malcolm MacDonnell
Try using
sScript = 'cmd /C move /y ' ;
Mal
Re: Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 1:10 am
by EvgenyT
Ok
Then do below:
DatasourceASCIIQuoteCharacter='';
sScript = 'move/y' ;
sImportdir = 'D:\TM1Model\Import\'|pFileName|'"';
sArchivedir = '"D:\TM1Model\Archive\"';
sCommand = sScript|' '|sImportDir|' '|sArchivedir;
ASCIIOUTPUT('Output path\test.bat',sCommand);
sScript = 'Output path\test.bat';
EXECUTECOMMAND( sScript , 0 ) ;
This way you can pass file name to the .bat script in your loop
Re: Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 1:11 am
by failurehappening
I think you need to use 'cmd /c' when executing commands
see below:
Code: Select all
sQuote = CHAR(34);
counter = 1;
sImportdir = 'D:\TM1Model\Import\';
sArchivedir = 'D:\TM1Model\Archive\' ;
WHILE ( Counter > 10 );
FileName = sImportdir | 'Test' | NumberToString ( Counter ) | '.txt';
CommandText = 'cmd /c move /y ' | sQuote | FileName | sQuote | ' ' | sArchivedir ;
Asciioutput ( 'debug.txt' , CommandText )
ExecuteCommand ( CommandText ,0 );
Counter = Counter +1 ;
END;
Re: Unable to do executecommand from TI
Posted: Tue Mar 10, 2015 2:04 am
by TM1New
@ Failurehappening.
Your code worked perfectly.
Thanks everyone for your time and efforts.
Cheers
Re: Unable to do executecommand from TI
Posted: Wed Mar 11, 2015 8:55 am
by Steve Rowe
AS Malcolm said prefixing your statement with cmd /c is the way to go, then you don't need to bother with batch files etc.
Re: Unable to do executecommand from TI
Posted: Thu Aug 06, 2015 9:48 am
by holger_b
Today, I came across this thread while I was trying to delete a data source file in the epilog (which is created in the prolog), and I struggled with this "file is in use" error. Here is how I finally did it:
Code: Select all
sBatchFile = '}tmp_my_del.bat';
ExecuteCommand('cmd /c echo sleep 10 > ' | sBatchFile, 1);
ExecuteCommand('cmd /c echo del ' | sDataSourceFile | ' >> ' | sBatchFile, 1);
ExecuteCommand('cmd /c echo del ' | sBatchFile | ' >> ' | sBatchFile, 1);
ExecuteCommand('cmd /c ' | sBatchFile, 0);
So the batch file even destroys itself in the end, which I had expected to be more complicated to do...
The problem with creating batch files using asciioutput by the way is, they will not be there immediately, but only after the commit, which often is too late.
Regards
Holger