Page 1 of 1

DEL Command is not working in TM1 Process

Posted: Tue Dec 25, 2018 3:26 pm
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.

Re: DEL Command is not working in TM1 Process

Posted: Tue Dec 25, 2018 7:15 pm
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.

Re: DEL Command is not working in TM1 Process

Posted: Tue Dec 25, 2018 7:27 pm
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.

Re: DEL Command is not working in TM1 Process

Posted: Tue Dec 25, 2018 7:33 pm
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.

Re: DEL Command is not working in TM1 Process

Posted: Thu Dec 27, 2018 11:43 am
by My24
Thanks a lot for your responses.
Both of two methods successfully work!

Re: DEL Command is not working in TM1 Process

Posted: Wed Jan 02, 2019 9:46 am
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.

Re: DEL Command is not working in TM1 Process

Posted: Sun May 15, 2022 4:29 pm
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);

Re: DEL Command is not working in TM1 Process

Posted: Sun May 15, 2022 5:08 pm
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.

Re: DEL Command is not working in TM1 Process

Posted: Mon May 16, 2022 1:08 am
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.

Re: DEL Command is not working in TM1 Process

Posted: Mon May 16, 2022 7:18 am
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.

Re: DEL Command is not working in TM1 Process

Posted: Mon May 16, 2022 7:31 am
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

Re: DEL Command is not working in TM1 Process

Posted: Mon May 16, 2022 10:29 am
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.

Re: DEL Command is not working in TM1 Process

Posted: Mon May 16, 2022 10:33 am
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

Re: DEL Command is not working in TM1 Process

Posted: Mon May 16, 2022 10:42 am
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.

Re: DEL Command is not working in TM1 Process

Posted: Mon May 16, 2022 12:17 pm
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.

Re: DEL Command is not working in TM1 Process

Posted: Mon May 16, 2022 12:24 pm
by MarenC
i have understood that
Glad someone has! ;)