Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

TCC Bug??

Nov
33
0
Hi guys, I've compiled a .btm batch with te latest version of Take Command (v29), and this .btm runs with the latest version of TCC-RT (v29).
This is the original .cmd batch:

Code:
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION

IF NOT EXIST "%~dp0FOLDER" (
PowerShell -Command "Write-Host [$(Get-Date -Format 'yyyy/dd/MM HH:mm:ss')] ERROR. -NoNewline">>"%~dp0LOG.log" & ECHO/>>"%~dp0LOG.log"
EXIT)
PUSHD "%~dp0FOLDER"
IF NOT EXIST "%~dp0FILE.ini" (
PowerShell -Command "Write-Host [$(Get-Date -Format 'yyyy/dd/MM HH:mm:ss')] ERROR. -NoNewline">>"%~dp0LOG.log" & ECHO/>>"%~dp0LOG.log"
EXIT)
...
other commands

As you can see, in the PowerShell Write-Host command I had to add "-NoNewline" followed by "ECHO/" so that I could have a proper carriage return.
The are 2 problems:

1) Launching the btm file, at least 3 times out of 10 (randomly) the log file after "ERROR." does not wrap.

2) In other cases, the btm file returns the error as output, but it does not exit and continues to run subsequent commands.

Wanting to maintain full compatibility with CMD, how should I set up the TCMD.ini file? And how could I solve the problems encountered?

Thanks!
 
I changed "EXIT" to "EXIT /B" and added a single "other commands" line. So I'm using this.

Code:
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION

IF NOT EXIST "%~dp0FOLDER" (
PowerShell -Command "Write-Host [$(Get-Date -Format 'yyyy/dd/MM HH:mm:ss')] ERROR. -NoNewline">>"%~dp0LOG.log" & ECHO/>>"%~dp0LOG.log"
EXIT /B)
PUSHD "%~dp0FOLDER"
IF NOT EXIST "%~dp0FILE.ini" (
PowerShell -Command "Write-Host [$(Get-Date -Format 'yyyy/dd/MM HH:mm:ss')] ERROR. -NoNewline">>"%~dp0LOG.log" & ECHO/>>"%~dp0LOG.log"
EXIT /B)
ECHO Other commands go here.

It works correctly in both CMD and TCC 29.00.17 x64. Output always goes to the log file and that file is always terminated with CRLF.

Is that a well-known problem with Write-Host (writing LF instead of CRLF)?

What is "ECHO/" ... is it documented anywhere?

I would put spaces on both sides of ">>".
 
I changed "EXIT" to "EXIT /B" and added a single "other commands" line. So I'm using this.

Code:
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION

IF NOT EXIST "%~dp0FOLDER" (
PowerShell -Command "Write-Host [$(Get-Date -Format 'yyyy/dd/MM HH:mm:ss')] ERROR. -NoNewline">>"%~dp0LOG.log" & ECHO/>>"%~dp0LOG.log"
EXIT /B)
PUSHD "%~dp0FOLDER"
IF NOT EXIST "%~dp0FILE.ini" (
PowerShell -Command "Write-Host [$(Get-Date -Format 'yyyy/dd/MM HH:mm:ss')] ERROR. -NoNewline">>"%~dp0LOG.log" & ECHO/>>"%~dp0LOG.log"
EXIT /B)
ECHO Other commands go here.

It works correctly in both CMD and TCC 29.00.17 x64. Output always goes to the log file and that file is always terminated with CRLF.

Is that a well-known problem with Write-Host (writing LF instead of CRLF)?

What is "ECHO/" ... is it documented anywhere?

I would put spaces on both sides of ">>".

Thanks you, now I try your code"

Here you can read about ECHO/: ECHO. FAILS to give text or blank line - Instead use ECHO/ - DosTips.com

About "Write-Host" I have not found other solutions for now, but I'm not a PowerShell expert

Why would you put spaces " >> " ?
 
Last edited:
P.S., You can force a proper newline like this.

Code:
IF NOT EXIST "%~dp0FOLDER" (
PowerShell -Command "Write-Host [$(Get-Date -Format 'yyyy/dd/MM HH:mm:ss')] ERROR.`r`n -NoNewLine" >> "%~dp0LOG.log"
EXIT /B)
 
Why would you put spaces " >> " ?
To me it's just good practice and it makes life simple. If there are rules for when you must_include/can_omit spaces around tokens, those rules are too numerous for me (and might differ from shell to shell). It also makes things easier to read.
 

Similar threads

Back
Top