Trying to figure out how to get the logic in a big Windows batch file to work right is about driving me crazy.
I keep running up against walls for the things that ought to be *simple*.
Like echoing a variable value.
Like comparing a variable to another value.
Sheeesh!
Consider the following.
-----------------------
for /f "tokens=1,2*" %%a in (tmp.txt) do (
SET var1=%%a
SET var2=%%b
SET var3=%%c
echo %%c xxx
setlocal enableDelayedExpansion
echo !var3!
echo "!var3!"
)
------------------------
Why does the 1st ECHO statement display an output with the 'xxx' *before* and partially *overlaying* the value that was read from the file, like this???
xxxIYUIYOIYI
The 2nd ECHO statement displays the correct value.
The 3rd ECHO statement displays the first double-quote character, then the correct variable value. But it doesn't display the 2nd double-quote character. WHY NOT??? How can I figure out if there are spaces on the end, if it doesn't let me display anything after it??
Heaven forbid what I really want to do is like this:
IF "!var3:~19!" == " " call :someOtherFunction
or like this:
IF "!var3:~-2!" == " " call :someOtherFunction
How can I figure out why the If statements aren't working, if I can't even get a simple ECHO to work right?
If I replace the double quote chars in the ECHO statement with some other chars, it still has the same problem.
It doesn't help that I was up til 2am working on this batch file last night, and was only able to get 5.5 hours sleep. Due to waking up early and not being able to fall back asleep.
On top of having woken up 1.5 hours early yesterday morning.
I keep running up against walls for the things that ought to be *simple*.
Like echoing a variable value.
Like comparing a variable to another value.
Sheeesh!
Consider the following.
-----------------------
for /f "tokens=1,2*" %%a in (tmp.txt) do (
SET var1=%%a
SET var2=%%b
SET var3=%%c
echo %%c xxx
setlocal enableDelayedExpansion
echo !var3!
echo "!var3!"
)
------------------------
Why does the 1st ECHO statement display an output with the 'xxx' *before* and partially *overlaying* the value that was read from the file, like this???
xxxIYUIYOIYI
The 2nd ECHO statement displays the correct value.
The 3rd ECHO statement displays the first double-quote character, then the correct variable value. But it doesn't display the 2nd double-quote character. WHY NOT??? How can I figure out if there are spaces on the end, if it doesn't let me display anything after it??
Heaven forbid what I really want to do is like this:
IF "!var3:~19!" == " " call :someOtherFunction
or like this:
IF "!var3:~-2!" == " " call :someOtherFunction
How can I figure out why the If statements aren't working, if I can't even get a simple ECHO to work right?
If I replace the double quote chars in the ECHO statement with some other chars, it still has the same problem.
It doesn't help that I was up til 2am working on this batch file last night, and was only able to get 5.5 hours sleep. Due to waking up early and not being able to fall back asleep.
On top of having woken up 1.5 hours early yesterday morning.
no subject
Date: 2014-03-22 09:45 pm (UTC)From:no subject
Date: 2014-03-22 10:06 pm (UTC)From:But I certainly shall look into that for the future, because "pain and suffering on grand scale" -YES.
My problem here is probably due to some EOL character being included in my variable. I finally used a workaround to get the variable set correctly, but now the batch file is still somehow adding back an extra space on the end when it writes it out again. ARGH.
no subject
Date: 2014-03-22 10:11 pm (UTC)From:(And for preference I write a simple command line app in C#, because I like that. But scripting languages are easier for simple things.)
no subject
Date: 2014-03-24 03:15 am (UTC)From:Otherwise, no, I have not a clue what's going on with that, sorry.
no subject
Date: 2014-03-24 12:54 pm (UTC)From:But in this case, I was piping the output of a DB2 query to a file, and then parsing in the results. The problem did seem to be to some line-break or other character on the end of the line... I had expected the batch file command I was using would filter that out, but I guess it didn't. I finally got it to work by trimming off the last character and then checking for spaces on the end and trimming them.
no subject
Date: 2014-03-24 12:59 pm (UTC)From:no subject
Date: 2014-03-25 02:52 am (UTC)From:no subject
Date: 2014-03-25 04:00 am (UTC)From:no subject
Date: 2014-03-25 04:53 am (UTC)From: