darkoshi: (Default)
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.

Date: 2014-03-22 09:45 pm (UTC)From: [personal profile] andrewducker
andrewducker: (Default)
Might I suggest that writing things in DOS batch files is asking for pain and suffering on a grand scale, and that you should either use the Windows Scripting Host with VBScript or Javascript, or switch to Powershell, either of which would work better in the long term...

Date: 2014-03-22 10:11 pm (UTC)From: [personal profile] andrewducker
andrewducker: (Default)
Yeah, we have a load of batch scripts for moving files around, and we moved all of the functionality out into javascript, because it was about 500 times less painful to do things in.

(And for preference I write a simple command line app in C#, because I like that. But scripting languages are easier for simple things.)

Date: 2014-03-24 03:15 am (UTC)From: [personal profile] marahmarie
marahmarie: (M In M Forever) (Default)
Perhaps a dumb question, but are you perchance using Notepad (the built-in Windows utility)? Because it...DOES...things...like that. I stopped editing .js files in it years ago once I realized it was...DOING...those things. The extra white space I did not add in myself, the line-breaks Notepad so lovingly chose for me, and the many other mystery-meat errors in formatting just totally broke my scripts, so I've used Notepad++ ever since (two years now and going strong) and I've never looked back.

Otherwise, no, I have not a clue what's going on with that, sorry.
Edited (dropped a word) Date: 2014-03-24 03:16 am (UTC)

Date: 2014-03-25 02:52 am (UTC)From: [personal profile] marahmarie
marahmarie: (M In M Forever) (Default)
Trying to trim off end spaces was the reason I had to switch. Notepad just would not let me do it; I'd fix one line only to have another below it break. And on and on throughout an entire script until finally, I couldn't take it anymore (oh and pro tip, you will see similar errors in IE textareas when you try to backspace or delete something, often resulting in entire lines getting eaten alive/involuntarily replaced as you type). When I googled for something to replace it, Notepad++ was at the top of search results; in spite of it being my first replacement, I've probably tried them all since then but Notepad++ has always worked out the best.
Edited Date: 2014-03-25 02:54 am (UTC)

Date: 2014-03-25 04:53 am (UTC)From: [personal profile] marahmarie
marahmarie: (M In M Forever) (Default)
Yeah, it's pretty darned neat. :)

January 2026

S M T W T F S
     123
45678910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Saturday, January 10th, 2026 12:08 pm
Powered by Dreamwidth Studios