0

If on the command line I execute:

c:\digitemp.exe -t0 -o%C -q > res1.txt 

res1.txt contains correctly the numerical temperature in Celsius (say: 24.23456). But if the same command is executed inside a bat file (say: test.bat):

@ECHO OFF ECHO Hola pootol! ECHO. c:\digitemp.exe -t0 -o%C -q > res1.txt rem set pootol = < res1.txt rem set pootol ECHO Prem una tecla per sortir. pause > null 

res1.txt contains a wrong Celsius value that I suspect is related to the argument " -o%C ". As you can see I rem the variable assing cause pootol var is wrong assigned with the Celsius value before it is mentioned. What am I doing wrong?

1
  • I have tried to fix some grammar and formatting mistakes in your question. However, I have not idea what "As you can see I rem the variable assing cause pootol var is wrong assigned with the Celsius value before it is mentioned" means. Can you try clarifying this yourself? Commented Jun 11, 2012 at 12:31

2 Answers 2

2

The problem in your case is the % sign, as it's evaluated different in the cmd-line and in batch files.
In batch files you can escape it with doubling it.

So your code looks like

c:\digitemp.exe -t0 -o%%C -q > res1.txt 
Sign up to request clarification or add additional context in comments.

Comments

0

In batch files % is used to denote variables. So %C is interpreted inside the batch file as a variable and replaced with its value. Since it doesn't have a value it is replaced with an empty string.

Use the caret ^ character to escape the % so that the interpreter treats the % as a normal character.

c:\digitemp.exe -t0 -o^%C -q > res1.txt 

2 Comments

thanks for the answer but i get the same result with the caret ^ escape char as you said. There is another scape character to try? Thanks again!
found it! thanks -o%%C (robvanderwoude.com/escapechars.php) it works now!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.