Search found 1059 matches

by jeb
02 Nov 2020 04:27
Forum: DOS Batch Forum
Topic: Nesting statement if ()==() ( ) gives an error
Replies: 2
Views: 6294

Re: Nesting statement if ()==() ( ) gives an error

Hi BoQsc, avoid enclosing anything with parenthesis in the IF's, at all. Enclosing should always be done with quotes. IF "c" == "c" ( echo test IF "b" == "b" ( echo yes ) ) Using quotes, avoids problems with spaces in the value (in case of variables) and also special characters cna be used. Parenthe...
by jeb
29 Oct 2020 07:58
Forum: DOS Batch Forum
Topic: A killer : in a comment
Replies: 15
Views: 19576

Re: A killer : in a comment

And this behaviour is a useful feature!

Code: Select all

%LOAD_ONLY_ONCE:call "%~dp0\libBase.cmd" := %
If LOAD_ONLY_ONCE is undefined, the call is executed and there the LOAD_ONLY_ONCE macro is defined.
Any further such line will execute only the macro.

jeb
by jeb
02 Aug 2020 12:01
Forum: DOS Batch Forum
Topic: FOR variable %%A in macro definition gets overridden when script is called by other script within FOR loop
Replies: 15
Views: 17999

Re: FOR variable %%A in macro definition gets overridden when script is called by other script within FOR loop

Thanks Maylow for the question :D I had the same problem some time ago, and it's because I built also a batch macro library :) a) It's expected behaviour b) It can be solved, It can be solved even that you can define macros inside any FOR-Loop and independent of delayed mode It doesn't need setlocal...
by jeb
16 Jul 2020 12:14
Forum: DOS Batch Forum
Topic: Assign cmdline output to var with inner cmdline quotes?
Replies: 10
Views: 12578

Re: Assign cmdline output to var with inner cmdline quotes?

Hi pstein, did you test your code with the macro from SO:Assign output of a program to a variable ? It should work without any modifications. The FOR/F loop uses a single quote and a double quote for /F "delims=" %%O in ('"%%~2 | findstr /N ^^"') do ( %\n% --- For beter visibility: ... %%O in ( ' " ...
by jeb
13 Jul 2020 01:32
Forum: DOS Batch Forum
Topic: Assign cmdline output to var with inner cmdline quotes?
Replies: 10
Views: 12578

Re: Assign cmdline output to var with inner cmdline quotes?

Hi T3rry, I suppose the $set is a macro, perhaps the one from SO: Assign output of a program to a variable using a MS batch file . But even then it should work with spaces, I tested it and it works for me with: call :initMacro %$set% output=""with space\calc.exe" -parm1 "https://www.foobar.com/web/p...
by jeb
22 Jun 2020 00:43
Forum: DOS Batch Forum
Topic: caret removes the first command after opening parenthesis if its concat'd to the first token of command without space
Replies: 4
Views: 6311

Re: caret removes the first command after opening parenthesis if its concat'd to the first token of command without spac

Btw. the @ has also sme impact.

Code: Select all

@echo on
cls
(
echo Start

@ ec^
ho #1: Works
@ec^
ho #2: Fails

@@^
@@ ec^
ho #3: Works

xyz@@^
@@ ec^
ho #4: Works
)

echo End
by jeb
22 Jun 2020 00:38
Forum: DOS Batch Forum
Topic: Pass multiple lines(through stdin) from batch to powershell
Replies: 4
Views: 8097

Re: Pass multiple lines(through stdin) from batch to powershell

Hi lockedscope, you found already the relevant posts on SO. Pipes (mostly) creates a child cmd.exe instance on both sides. The command itself will be executed in the child instance, but the first expansion occurs in the parent instance. The parent instance will use the percent expansion, but the del...
by jeb
22 Jun 2020 00:30
Forum: DOS Batch Forum
Topic: How batch parsing phases work?
Replies: 4
Views: 5790

Re: How batch parsing phases work?

Hi,

your first analysis is correct, but not the second one.

the line: set c=^^^!text^^^!
assigns !text! to c

Therefore the line: echo %c%

only has to expand !text! to "my"
by jeb
22 Jun 2020 00:20
Forum: DOS Batch Forum
Topic: caret removes the first command after opening parenthesis if its concat'd to the first token of command without space
Replies: 4
Views: 6311

Re: caret removes the first command after opening parenthesis if its concat'd to the first token of command without spac

Hi lockedscope, nice finding :!: I didn't knew that and never tested it. The rule seems to be: - In paremthesis: - If a caret+line feed splits the command token (usually the first token), then only the part after the last LF is used - This rule is true for any position in the parenthsis, not only th...
by jeb
16 Jun 2020 00:09
Forum: DOS Batch Forum
Topic: How batch parsing phases work?
Replies: 4
Views: 5790

Re: How batch parsing phases work?

Hi lockedscope, it's quite correct. But my first rule is: Always monitor variables unmodified :!: You can use delayed expansion for that or the SET command, but never percent expansion, that only confuses the result 8) If you add set b after the line set "b=%a%" you see that the content of <b> is "^...
by jeb
15 Jun 2020 07:17
Forum: DOS Batch Forum
Topic: Dynamic loop code over multiple lines causes extra quotes
Replies: 7
Views: 7650

Re: Dynamic loop code over multiple lines causes extra quotes

Hi lockedscope, So, how could that 10/11 carets works? The problem is, in your case there are multiple escape phases! Start: "for... "^^^^^^^^^^!text^^^^^^^^^^! ...." phase2: "for... "^^^^^!text^^^^^! ..." phase5: "for... "^^!text^^! ..." CALL doubling: "for... "^^^^!text^^^^! ..." Restart parsing p...
by jeb
13 Jun 2020 10:31
Forum: DOS Batch Forum
Topic: How delayed expansion works?
Replies: 3
Views: 4937

Re: How delayed expansion works?

Hi lockedscope,

yes your eplanation is correct.
Percent expansion is always the first one and can't be suppressed.
Then the for-variables expansion occurs.
And the last expansion can be the delayed expansion, if enabled.

jeb
by jeb
11 Jun 2020 05:27
Forum: DOS Batch Forum
Topic: Is there a way to split a string to new lines in file by delimiter
Replies: 4
Views: 9457

Re: Is there a way to split a string to new lines in file by delimiter

Hi brentonv, you link to SO Split values into separate lines for each delimiter - batch shows already a working solution :D @echo off setLocal EnableDelayedExpansion for /f "delims=" %%a in (string.txt) do ( set "line=%%a" echo reading line: !line! for /F "delims=" %%C in (""!line:^:^=^"^ "!"^") do ...
by jeb
15 May 2020 00:00
Forum: DOS Batch Forum
Topic: Debugging / syntax checksing tools for batch
Replies: 27
Views: 34191

Re: Debugging / syntax checksing tools for batch

Hi Yanta, if you don't know the line where the error occurs, you could add markers like echo Line: 123 >> debug.txt ... echo Line: 456 >> debug.txt Add these markers until you know the exactly line number. The rest should be easy. It should be possible to add the markers automatically with JREPL to ...
by jeb
11 May 2020 00:38
Forum: DOS Batch Forum
Topic: able to run functions from another script?
Replies: 4
Views: 6391

Re: able to run functions from another script?

Hi deusery, yes you can. There are different solutions to build a batch library, but no perfect one. 1) You can use a HACK/bug/feature of cmd.exe If you call a label in the same file and then start a second batch file without CALL, then the label will be jumped to also in the second batch file! batc...