DEL Command is not working in TM1 Process

Post Reply
My24
Posts: 18
Joined: Tue Dec 12, 2017 2:57 pm
OLAP Product: TM1
Version: PA 2.0
Excel Version: Excel 2016

DEL Command is not working in TM1 Process

Post by My24 »

Hi all!

I am trying to create a file in prolog and and delete the file in Epilog of a process.
But when I am trying to delete the "test.txt" file, the process is aborted and gives the error of "The system cannot find the file specified."

Also when I run the command of DEL "C:\Program Files\ibm\cognos\tm1_64\samples\tm1\PlanSamp\test.txt" from cmd, the file is deleted but I want to delete the file with TI.

Could you help me about this problem?

The code is the following:

Code: Select all

Prolog:

vFilePath = 'C:\Program Files\ibm\cognos\tm1_64\samples\tm1\PlanSamp\test.txt';

ASCIIOUTPUT(vFilePath, '');

EXECUTECOMMAND('TIMEOUT 5', 1);



Epilog:


vCommand = 'DEL '|'"' | vFilePath| '"';
ASCIIOUTPUT('CommandLog.txt', vCommand);
ExecuteCommand(vCommand, 1);


Regards.
User avatar
Alan Kirk
Site Admin
Posts: 6606
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: DEL Command is not working in TM1 Process

Post by Alan Kirk »

Del is a command which is internal to the command line processor.

The usual way around this is to create a generic batch file with a parameter, such as:

Code: Select all

del %1
which then allows you to use ExecuteCommand to call that batch file. The second argument that you pass (separated by a space) is the name of the file that you want to delete, which will be passed into the %1 variable.
"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.
Wim Gielis
MVP
Posts: 3105
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: DEL Command is not working in TM1 Process

Post by Wim Gielis »

2 remarks.
You can use the function AsciiDelete.
If you want to use ExecuteCommand with creating a text file, create the file in the Prolog tab and execute it in the Epilog tab. Then delete the temporary text file again.
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
User avatar
Alan Kirk
Site Admin
Posts: 6606
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: DEL Command is not working in TM1 Process

Post by Alan Kirk »

Wim Gielis wrote: Tue Dec 25, 2018 7:27 pm 2 remarks.
You can use the function AsciiDelete.
Good point.
Wim Gielis wrote: Tue Dec 25, 2018 7:27 pm If you want to use ExecuteCommand with creating a text file, create the file in the Prolog tab and execute it in the Epilog tab. Then delete the temporary text file again.
I was originally going to mention that but then on further examination that didn't appear to be what they were trying to do. The AsciiOutput looks like it's just debugging code (note the name CommandLOG) rather than trying to create a batch file. If it is, though, it would run into two additional problems:
(a) It won't work with a .txt extension, it would need to be a .bat one; and
(b) Unless the quote character is modified either by using a command in the prolog or in the data source tab, if available, the command would by default come out wrapped in double quotes.

And a command that is wrapped entirely in double quotes is going nowhere.
"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.
My24
Posts: 18
Joined: Tue Dec 12, 2017 2:57 pm
OLAP Product: TM1
Version: PA 2.0
Excel Version: Excel 2016

Re: DEL Command is not working in TM1 Process

Post by My24 »

Thanks a lot for your responses.
Both of two methods successfully work!
User avatar
Steve Rowe
Site Admin
Posts: 2410
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: DEL Command is not working in TM1 Process

Post by Steve Rowe »

Also

Code: Select all

vCommand = 'cmd /c DEL '|'"' | vFilePath| '"';
ExecuteCommand(vCommand, 0);

would work with no need for text files.
Take care with using the ExecuteCommand function with the 1 parameter set, very occasionally DOS will hang and then your TI will get stuck.
Unless you have a good reason use the 0 qualifier and then your TI won't get stuck.
Technical Director
www.infocat.co.uk
Niko
Posts: 50
Joined: Tue Feb 15, 2022 6:43 am
OLAP Product: IBM Cognos TM1
Version: PA 2.09 / TM1 11.7.00000.42
Excel Version: EXCEL 2019
Location: Asia

Re: DEL Command is not working in TM1 Process

Post by Niko »

My command that is wrapped entirely in double quotes is going nowhere.
i want to delete the folder ,subfolder and all files in that folder.
So it doesnot work , i want to solve the problem

i input the script below in the windows cmd manually ,it works well.
##
rd/s/q D:\backup\Sales
##

then i input the script below in the TI Process manually , execute failed , server log show : "The system cannot find the file specified".
i guess the quotes Cause the result , so who can help me? thankyou first.
[Prolog]
sBackupDir = 'D:\backup\Sales';
sDelCmd = 'rd/s/q '| sBackupDir ;
[Epilog]
ExecuteCommand( sDelCmd ,1);
User avatar
gtonkin
MVP
Posts: 1192
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: DEL Command is not working in TM1 Process

Post by gtonkin »

Have you tried uisng CMD /C first?

Code: Select all

sDelCmd = 'cmd /c rd /s /q '| sBackupDir ;
Also, not seeing spaces between rd and the parameters.
Niko
Posts: 50
Joined: Tue Feb 15, 2022 6:43 am
OLAP Product: IBM Cognos TM1
Version: PA 2.09 / TM1 11.7.00000.42
Excel Version: EXCEL 2019
Location: Asia

Re: DEL Command is not working in TM1 Process

Post by Niko »

gtonkin wrote: Sun May 15, 2022 5:08 pm Have you tried uisng CMD /C first?

Code: Select all

sDelCmd = 'cmd /c rd /s /q '| sBackupDir ;
Also, not seeing spaces between rd and the parameters.



Thank u first.i will try later today,and i will share the result to you.
Niko
Posts: 50
Joined: Tue Feb 15, 2022 6:43 am
OLAP Product: IBM Cognos TM1
Version: PA 2.09 / TM1 11.7.00000.42
Excel Version: EXCEL 2019
Location: Asia

Re: DEL Command is not working in TM1 Process

Post by Niko »

Niko wrote: Mon May 16, 2022 1:08 am
gtonkin wrote: Sun May 15, 2022 5:08 pm Have you tried uisng CMD /C first?

Code: Select all

sDelCmd = 'cmd /c rd /s /q '| sBackupDir ;
Also, not seeing spaces between rd and the parameters.


Thank you very much. I add cmd /c before the command,it works well.And i want to know the reason why i should add cmd /c ,i am very confused.



Thank u first.i will try later today,and i will share the result to you.
MarenC
Regular Participant
Posts: 346
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: DEL Command is not working in TM1 Process

Post by MarenC »

Hi,

You say you want to delete all files in the folder, but when I read the rd docs, it states:
You can't delete a directory that contains files, including hidden or system files
Did you consider using powershell? So this in your TI instead:

sDelCmd = 'Powershell Remove-Item -LiteralPath "FolderNameHere" -Force -Recurse';

I read somewhere that it is better to use ExecuteCommand with 0 instead of 1, but use sleep in conjunction, so

ExecuteCommand( sDelCmd , 0);
Sleep(1000);

Happy to be corrected on this latter point.

Maren
Niko
Posts: 50
Joined: Tue Feb 15, 2022 6:43 am
OLAP Product: IBM Cognos TM1
Version: PA 2.09 / TM1 11.7.00000.42
Excel Version: EXCEL 2019
Location: Asia

Re: DEL Command is not working in TM1 Process

Post by Niko »

MarenC wrote: Mon May 16, 2022 7:31 am Hi,

You say you want to delete all files in the folder, but when I read the rd docs, it states:
You can't delete a directory that contains files, including hidden or system files
Did you consider using powershell? So this in your TI instead:

sDelCmd = 'Powershell Remove-Item -LiteralPath "FolderNameHere" -Force -Recurse';

I read somewhere that it is better to use ExecuteCommand with 0 instead of 1, but use sleep in conjunction, so

ExecuteCommand( sDelCmd , 0);
Sleep(1000);

Happy to be corrected on this latter point.

Maren
Thank you for your advice, because I want to wait for the completion of the deletion command,and then to delete the BAT file containing the deletion command. if I delete the BAT file before the command is executed completely, i guess i will not be able to delete the folder successfully. So i am suprise for that if i execute the bat file ,sleep(1000) and delete the bat file immediately, whether the command can be executed successfully? Look forward your reply,thank u first.
MarenC
Regular Participant
Posts: 346
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: DEL Command is not working in TM1 Process

Post by MarenC »

Hi,

You don't need a BAT file, you just add that code into the TI process, and forget about the batch file.

Simply running the TI should do the deletion.

Maren
User avatar
gtonkin
MVP
Posts: 1192
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: DEL Command is not working in TM1 Process

Post by gtonkin »

Niko wrote: Mon May 16, 2022 7:18 am ...
Thank you very much. I add cmd /c before the command,it works well.And i want to know the reason why i should add cmd /c ,i am very confused.
...
CMD /C should create a new command line instance/context (new process) and run the command there for you. This may change some of the environment variables/inheritance etc. I typically start with CMD /C to start a new process which runs and terminates when complete.
Niko
Posts: 50
Joined: Tue Feb 15, 2022 6:43 am
OLAP Product: IBM Cognos TM1
Version: PA 2.09 / TM1 11.7.00000.42
Excel Version: EXCEL 2019
Location: Asia

Re: DEL Command is not working in TM1 Process

Post by Niko »

gtonkin wrote: Mon May 16, 2022 10:42 am
Niko wrote: Mon May 16, 2022 7:18 am ...
Thank you very much. I add cmd /c before the command,it works well.And i want to know the reason why i should add cmd /c ,i am very confused.
...
CMD /C should create a new command line instance/context (new process) and run the command there for you. This may change some of the environment variables/inheritance etc. I typically start with CMD /C to start a new process which runs and terminates when complete.
OKay,i have understood that , thank u again.
MarenC
Regular Participant
Posts: 346
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: DEL Command is not working in TM1 Process

Post by MarenC »

i have understood that
Glad someone has! ;)
Post Reply