Yes, but it is simply that an IF statement doesn't use DO, DO is part of a FOR statement. DO on its own isn't anything.
foxidrive, what's the purpose of using two find's? Wouldn't [find /c /i "process.exe"] work? I didn't change that in my posts because I assumed you had a reason.
Are you changing "process.exe" to be the name of the process you're checking for? Also, GTR 2 should be GEQ 2 (if you want it to match LSS 2, and you can just use else instead, or omit the goto:continue entirely if :continue is immediately after the for loop). Not that either of those woul...
If you have timeout available, and you're only going to use this batch file on computers where you know timeout is available, just use timeout instead of ping. Using ping as a sleep/wait command is a compatibility hack mainly for XP.
The ping adds a delay between loops. It's not actually pinging anything meaningful, just your own computer (localhost) 60 times. You really don't want tasklist (and then 2 finds, and the supporting cmd.exe instances to support the piping) pounding away in batch in a constant loop without some sort o...
Also in line with this, as per http://www.dostips.com/forum/viewtopic.php?f=3&t=4312 if you use a cmdcmdline substring / string replacement to ''empty'' the cmdcmdline env var, it will still count as ''defined'' even if it is an empty string. rem [%cmdcmdline:~0,0%] echo [%cmdcmdline%] if define...
Wow, if I point one of the temp file variants at my RAM drive, it is hilariously fast; I don't think any of the in-batch processing variants can beat that. Very good point though: when we can expect delayedexpansion to be enabled, a function that works on the string directly, non-destructively, gets...
After searching for strlen threads, this one seems the most appropriate place to put this. Building on all previous work in this thread (so very little here is my work), here's my take on strlen: :strlen ( setlocal enabledelayedexpansion & set /a "}=0" if defined %~1 ( for %%# in (4096...
%cmdcmdline% often contains quotation marks, so you'd need to handle them first (such as with :: %cmdcmdline:"=*% ), but otherwise, yes, if "%cmdcmdline:~0,-1%" neq "" goto :loop will zero-fill the GetCommandLineW memory location, but I don't think it's affecting GetCommand...
Just some fun stuff before I hit the hay: @echo off echo %cmdcmdline% echo; echo;|echo %%cmdcmdline%% echo; set cmdcmdline=%cmdcmdline% echo %cmdcmdline:~1,5% set cmdcmdline= echo %cmdcmdline% echo; :: %cmdcmdline:.=,% echo %cmdcmdline:"=%&echo %cmdcmdline:~1,5%&call(%cmdcmdline:* =!%&a...
Good idea :idea: , that explains why some of my tests fails. C:\temp>echo %cmdcmdline:*C=X-123456789012345678901234567890% X-123456789012345678901234567890md C:\temp>cmd #### Here a message box pops up with "cmd.exe application error" ... (translated from german) ##### C:\temp> jeb I coul...
Using call for the errorlevel was a happy accident. When I originally set out to do this, my ideal result had been a stand-alone %or% , so I was trying all sorts of terrible things to break the parser (if only ascii 0x1A could also work its magic via environment variable!). At one point, I was tryin...
A quick preface: I enjoy batch's ubiquity, and so while I mostly work with 32-bit x86 assembly, C++ and the occasional interpreted language, I do a fair bit of goofy small projects with batch. Something that always bugged me was how strict batch's IF statement parenthesis were. Namely, I prefer the ...
Ah ha! Thanks. I hadn't quite put 2 and 2 together; particularly, I hadn't grasped in what way it'd mix both batch and cmd parsing. I've been referencing your guys' work (particularly on stackoverflow) for what feels like years at this point, but only recently realized this was where a good bit of b...