Unable to do executecommand from TI

Post Reply
TM1New
Posts: 23
Joined: Wed Feb 01, 2012 5:46 pm
OLAP Product: TM1
Version: 9.4
Excel Version: 2007

Unable to do executecommand from TI

Post 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
Alan Kirk
Site Admin
Posts: 6647
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: Unable to do executecommand from TI

Post 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.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
EvgenyT
Community Contributor
Posts: 324
Joined: Mon Jul 02, 2012 9:39 pm
OLAP Product: TM1
Version: PAL 2.0.8
Excel Version: 2016
Location: Sydney, Australia

Re: Unable to do executecommand from TI

Post 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
Last edited by EvgenyT on Tue Mar 10, 2015 12:32 am, edited 1 time in total.
TM1New
Posts: 23
Joined: Wed Feb 01, 2012 5:46 pm
OLAP Product: TM1
Version: 9.4
Excel Version: 2007

Re: Unable to do executecommand from TI

Post 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
TM1New
Posts: 23
Joined: Wed Feb 01, 2012 5:46 pm
OLAP Product: TM1
Version: 9.4
Excel Version: 2007

Re: Unable to do executecommand from TI

Post 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
EvgenyT
Community Contributor
Posts: 324
Joined: Mon Jul 02, 2012 9:39 pm
OLAP Product: TM1
Version: PAL 2.0.8
Excel Version: 2016
Location: Sydney, Australia

Re: Unable to do executecommand from TI

Post by EvgenyT »

Hi There,

So, what are you telling me is that you want to archive all the files in the folder?

ET
TM1New
Posts: 23
Joined: Wed Feb 01, 2012 5:46 pm
OLAP Product: TM1
Version: 9.4
Excel Version: 2007

Re: Unable to do executecommand from TI

Post 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
Malcolm MacDonnell
Posts: 26
Joined: Thu May 29, 2008 2:58 am

Re: Unable to do executecommand from TI

Post by Malcolm MacDonnell »

Try using

sScript = 'cmd /C move /y ' ;

Mal
EvgenyT
Community Contributor
Posts: 324
Joined: Mon Jul 02, 2012 9:39 pm
OLAP Product: TM1
Version: PAL 2.0.8
Excel Version: 2016
Location: Sydney, Australia

Re: Unable to do executecommand from TI

Post 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
failurehappening
Posts: 78
Joined: Tue Nov 30, 2010 1:18 am
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2010

Re: Unable to do executecommand from TI

Post 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;
RHR
TM1New
Posts: 23
Joined: Wed Feb 01, 2012 5:46 pm
OLAP Product: TM1
Version: 9.4
Excel Version: 2007

Re: Unable to do executecommand from TI

Post by TM1New »

@ Failurehappening.

Your code worked perfectly.

Thanks everyone for your time and efforts.

Cheers
User avatar
Steve Rowe
Site Admin
Posts: 2456
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Re: Unable to do executecommand from TI

Post 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.
Technical Director
www.infocat.co.uk
holger_b
Posts: 131
Joined: Tue May 17, 2011 10:04 am
OLAP Product: TM1
Version: Planning Analytics 2.0
Excel Version: 2016
Location: Freiburg, Germany

Re: Unable to do executecommand from TI

Post 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
Post Reply