ExecuteCommand()

Post Reply
mags88
Posts: 24
Joined: Wed Sep 14, 2011 11:59 pm
OLAP Product: TM1 Cognos
Version: 9.5.1
Excel Version: 2007

ExecuteCommand()

Post by mags88 »

Hi,

Just a quick question regarding ExecuteCommand() TI function. I'm trying to move a file between one location to another. The function works perfectly when I type in the file in the source folder. I would like to add a variable to ExecuteCommand() function instead of the exact file name. To clarify:

Code: Select all

ExecuteCommand('robocopy /move c:\origin c:\destination TestA.txt', 0);
This works fine. I would like to do the following:

Code: Select all

vFileName = 'TestA.txt';
vCmd = 'robocopy /move c:\origin c:\destination vFilename';
ExecuteCommand(vCmd,0);
The process runs fine, it just doesn't move the file TextA.txt. I've concluded, it is because instead of reading vFileName as a variable, the process searches for a filename that corresponds to vFileName in the origin folder and obviously no file is found to match that search criterion.

What puzzles me is that you can add a variable (vCmd) to the ExecuteCommand() function but you cannot add the variable (vFilename) to robocopy. Is there a way to move the file using the ExecuteCommand() function using variables instead of the exact file name. The reason I want to use variables instead of the exact file name is because this ExecuteCommond() function is going to be at the end part of a loop that will move the files after the T.I. has finished with them.

Regards,
Magnus
Gregor Koch
MVP
Posts: 263
Joined: Fri Jun 27, 2008 12:15 am
OLAP Product: Cognos TM1, CX
Version: 9.0 and up
Excel Version: 2007 and up

Re: ExecuteCommand()

Post by Gregor Koch »

You can either try this

vCmd = 'robocopy /move c:\origin c:\destination ' | vFilename;

Edit: Sorry was missing a space after destination in the code

This will concatenate the two parts of your command string rather than trying to copy to the file 'vFilename'.
Or you can parametrise a batch file that sits outside TM1, the former is probably easier as you are almost there.

Cheers
mags88
Posts: 24
Joined: Wed Sep 14, 2011 11:59 pm
OLAP Product: TM1 Cognos
Version: 9.5.1
Excel Version: 2007

Re: ExecuteCommand()

Post by mags88 »

Hi Gregor,

Using the concat function just creates a new destination folder called [original destination]|[filename]. The robocopy /move also moves everything that is in the origin folder into the new folder (as the function doesn't see a source file to copy). I am also trying to get the batch file method to work too, but the similar problem arises. I want the batch file to just move one file not all files in the origin folder.

Could anyone help me with the correct terminology to use, so that batch file picks up only one file (a bit like what wildcardfilesearch function does in TI.) Using the wildcard *, it searches for the first file after the wildcard and not all. Currently my batch file moves all files in the folder into a new folder. Again I do not want to code in the full filename for my batch file, as it will be used in a TI WHILE process and I will not know the full name or how many files there will be.

Regards,
Magnus
tomok
MVP
Posts: 2836
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: ExecuteCommand()

Post by tomok »

mags88 wrote:Could anyone help me with the correct terminology to use, so that batch file picks up only one file (a bit like what wildcardfilesearch function does in TI.) Using the wildcard *, it searches for the first file after the wildcard and not all. Currently my batch file moves all files in the folder into a new folder. Again I do not want to code in the full filename for my batch file, as it will be used in a TI WHILE process and I will not know the full name or how many files there will be.
Perhaps you should Google for help on Robocopy?????
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
Gregor Koch
MVP
Posts: 263
Joined: Fri Jun 27, 2008 12:15 am
OLAP Product: Cognos TM1, CX
Version: 9.0 and up
Excel Version: 2007 and up

Re: ExecuteCommand()

Post by Gregor Koch »

Hi
If your example code is working and you use my code, including the space/blank, I don't see how this shouldn't be working.
Maybe post the real folder names, file name and code you are using, as something might get lost in translation.
Other than that... same as what tomok said.
Cheers
rmackenzie
MVP
Posts: 733
Joined: Wed May 14, 2008 11:06 pm

Re: ExecuteCommand()

Post by rmackenzie »

Without seeing the real filenames etc, we are only guessing!... Perhaps you should use this code, just in case your variable filenames have spaces in their paths:

Code: Select all

vFileName = 'c:\something like\this sort of\filename\with spaces.txt';
vQuotedFileName = CHAR(34) | vFileName | CHAR(34);
vCmd = 'robocopy /move c:\origin c:\destination ' | vQuotedFilename';
ExecuteCommand(vCmd,0);
Robin Mackenzie
mags88
Posts: 24
Joined: Wed Sep 14, 2011 11:59 pm
OLAP Product: TM1 Cognos
Version: 9.5.1
Excel Version: 2007

Re: ExecuteCommand()

Post by mags88 »

Hi,

Thanks for everyone's advice, this works fine now.
User avatar
qml
MVP
Posts: 1096
Joined: Mon Feb 01, 2010 1:01 pm
OLAP Product: TM1 / Planning Analytics
Version: 2.0.9 and all previous
Excel Version: 2007 - 2016
Location: London, UK, Europe

Re: ExecuteCommand()

Post by qml »

mags88 wrote:Hi,

Thanks for everyone's advice, this works fine now.
As a matter of courtesy, are you able to write how you solved your problem in the end? This could help someone browsing this forum.
Kamil Arendt
Gregor Koch
MVP
Posts: 263
Joined: Fri Jun 27, 2008 12:15 am
OLAP Product: Cognos TM1, CX
Version: 9.0 and up
Excel Version: 2007 and up

Re: ExecuteCommand()

Post by Gregor Koch »

Seconded.
Bit curious what the error was.
mags88
Posts: 24
Joined: Wed Sep 14, 2011 11:59 pm
OLAP Product: TM1 Cognos
Version: 9.5.1
Excel Version: 2007

Re: ExecuteCommand()

Post by mags88 »

Sorry for the delay,

My goal was to get TI to find a file (a file that I would not know the name of) upload the data from said .csv file, once data had been uploaded into a cube, move said .csv file then loop the process so it looks for the next file in the source folder, uploads the next .csv file, moves and finds the next one (on loop until no more files found). Here is my T.I.

Code: Select all

vPrevFile = '';
vWild = WildcardFileSearch('C:\dest\*.csv', vPrevFile);
vDate = Today |'_';
vNWild = INSRT(vDate, vWild, 1);
vNFileName = INSRT('Processed_', vNWild, 1);

while (~(vWild @= ''));

#ExecuteProcess('SlaveProcess', 'filename', vWild);
vCmdRename = 'c:\dest\Batch3.bat '| vWild | ' ' | vNFileName;
ExecuteCommand(vCmdRename, 1);


vWild = WildcardFileSearch('C:\dest\*.csv', vPrevFile);
vNWild = INSRT(vDate, vWild, 1);
vNFileName = INSRT('Processed_', vNWild, 1);

End;
the slave process simply uploads the data from the found .csv file

the batch file is a simple batch file that renames the .csv file and moves it to a destination folder, by using the move command (not robocopy).
Post Reply