Search found 3577 matches

by aGerman
06 Oct 2019 07:00
Forum: DOS Batch Forum
Topic: If one of two files exist then do something.
Replies: 16
Views: 490

Re: If one of two files exist then do something.

Easiest method to work around logical OR is using a helper variable. set "oneExists=" if exist "%userprofile%\Desktop\file1.exe" set "oneExists=1" if exist "%userprofile%\Desktop\file2.exe" set "oneExists=1" if not defined oneExists ( rem your message and exit ) rem continue here But you could also ...
by aGerman
06 Oct 2019 06:44
Forum: DOS Batch Forum
Topic: Thoughts on this alternative method of obtaining cmdcmdline arguments (safe for all characters?)
Replies: 14
Views: 771

Re: Thoughts on this alternative method of obtaining cmdcmdline arguments (safe for all characters?)

That seems to be working (both scripts).
@koko consider to add an EXIT or EXIT /B after PAUSE in order to protect you from running the :len routine even if you are actually already done.

Steffen
by aGerman
05 Oct 2019 17:16
Forum: DOS Batch Forum
Topic: Thoughts on this alternative method of obtaining cmdcmdline arguments (safe for all characters?)
Replies: 14
Views: 771

Re: Thoughts on this alternative method of obtaining cmdcmdline arguments (safe for all characters?)

(I've also found that depending on which was the actual file dragged and dropped onto a script, among a selection of highlighted files, changes the order of the arguments). That's absolutely okay since it also changes the order in cmdcmdline. You can't do anything to prevent this rearrangement. Ste...
by aGerman
05 Oct 2019 16:42
Forum: DOS Batch Forum
Topic: Thoughts on this alternative method of obtaining cmdcmdline arguments (safe for all characters?)
Replies: 14
Views: 771

Re: Thoughts on this alternative method of obtaining cmdcmdline arguments (safe for all characters?)

Found that &( is the deadly culprit.
Interesting! I'll keep that in mind.

There's still something wrong in you current version.
scrnsht.png
scrnsht.png (44.56 KiB) Viewed 518 times
The first argument consists of several paths.

Steffen
by aGerman
05 Oct 2019 15:06
Forum: DOS Batch Forum
Topic: Automatically escaping strings to survive multiple parsings
Replies: 3
Views: 280

Re: Automatically escaping strings to survive multiple parsings

So maybe you're right and escaping the ( is not necessary. But apparently it works with it too. :) Oh, of course it works. My question goes in the direction of performance of your code and the limited string length in Batch. Both could be positively influenced. So apparently my dream of automating ...
by aGerman
05 Oct 2019 11:53
Forum: DOS Batch Forum
Topic: Automatically escaping strings to survive multiple parsings
Replies: 3
Views: 280

Re: Automatically escaping strings to survive multiple parsings

Nice piece of code, Jean-François! Unfortunately things are not always that simple. @echo off &setlocal DisableDelayedExpansion for /f %%i in ('for /f %%j in ('for /f %%k in ('echo a^^^^^^^&echo b'^^^) do @echo %%k'^) do @echo %%j') do echo ***%%i*** pause If you want to write a nestet FOR /F like t...
by aGerman
05 Oct 2019 08:43
Forum: DOS Batch Forum
Topic: Thoughts on this alternative method of obtaining cmdcmdline arguments (safe for all characters?)
Replies: 14
Views: 771

Re: Thoughts on this alternative method of obtaining cmdcmdline arguments (safe for all characters?)

perhaps wishful thinking Yes, unfortunately. The problem you are facing is still caused by the ampersand bug. If you drag/drop a file with the name you provided to a script that consists of nothing but @pause , the cmd will still crash. You don't even have any chance to access the cmdcmdline variab...
by aGerman
05 Oct 2019 07:46
Forum: DOS Batch Forum
Topic: [Solved] How to escape special characters on InputFile with Drag and Drop ?
Replies: 5
Views: 325

Re: How to escape special characters on InputFile with Drag and Drop ?

Now that koko reminds me ... there is a recent thread about parsing of cmdcmdline. viewtopic.php?f=3&t=9285 I didn't do any examination of the code yet. But maybe you could give some feedback of how it works for you.

Steffen
by aGerman
05 Oct 2019 06:36
Forum: DOS Batch Forum
Topic: [Solved] How to escape special characters on InputFile with Drag and Drop ?
Replies: 5
Views: 325

Re: How to escape special characters on InputFile with Drag and Drop ?

As I said, even that should work as long as you have a space somewhere in the path. Otherwise it's getting complicated. @echo off &setlocal DisableDelayedExpansion setlocal EnableDelayedExpansion set "params=!cmdcmdline:~,-1!" set "params=!params:*" =!" if "!params!"=="" exit endlocal&set "params=%p...
by aGerman
05 Oct 2019 06:15
Forum: DOS Batch Forum
Topic: [Solved] How to escape special characters on InputFile with Drag and Drop ?
Replies: 5
Views: 325

Re: How to escape special characters on InputFile with Drag and Drop ?

Could you provide the absolute path of a file where you are facing an error? The only real problems I can think of are a) The ampersand bug of cmd.exe. It occurs if a path contains an ampersand but no space that triggers quoting of the path. You would need a complicated processing of the cmdcmdline ...
by aGerman
03 Oct 2019 13:08
Forum: DOS Batch Forum
Topic: Running .exe from another cmd prompt not working properly.
Replies: 6
Views: 315

Re: Running .exe from another cmd prompt not working properly.

You want to do something "when the FileName.exe has finished". But the script doesn't wait for the FileName.exe process if you use the START command. The script just continues with the next line regardless whether or not FileName.exe still runs. My conclusion was that you need to run FileName.exe sy...
by aGerman
03 Oct 2019 12:54
Forum: DOS Batch Forum
Topic: Running .exe from another cmd prompt not working properly.
Replies: 6
Views: 315

Re: Running .exe from another cmd prompt not working properly.

If you don't want to run FileName.exe asynchronously, why do you use START rather than CALL? Or at least use START /WAIT.

Steffen
by aGerman
02 Oct 2019 14:09
Forum: DOS Batch Forum
Topic: Extract last run CheckSUR results
Replies: 2
Views: 251

Re: Extract last run CheckSUR results

Just use a FOR /F loop.

Code: Select all

@echo off &setlocal
for /f "usebackq delims=" %%i in ("C:\Windows\Logs\CBS\CheckSUR.log") do set "recent=%%i"
echo %recent%
pause
Depending on the size of the file it may take a while. I can't test the script since that log file doesn't exist on my machine.

Steffen
by aGerman
01 Oct 2019 09:34
Forum: DOS Batch Forum
Topic: non-buffering FOR /F alternative
Replies: 7
Views: 632

Re: non-buffering FOR /F alternative

I think I know the reason but didn't try yet. I registered the BeforeClosing routine in order to release memory and handles even if you close the window. SetConsoleCtrlHandler(BeforeClosing, TRUE); I call it actively if some errors occur, elsewise it is a callback function which was sub-classed from...