Search found 1042 matches

by jeb
13 Nov 2023 04:59
Forum: DOS Batch Forum
Topic: ECHOing to a file without a trailing space
Replies: 6
Views: 20792

Re: ECHOing to a file without a trailing space

With DelayedExpansion it's safe with all character, but then you don't need the FOR /F

Code: Select all

@echo off
setlocal DisableDelayedExpansion
set field1=a
set field2=(a
set field3=2
set field4=34564119
setlocal EnableDelayedExpansion

(echo(!field1!;!field2!;!field3!;!field4!) >"file4.tmp"
by jeb
10 Nov 2023 12:36
Forum: DOS Batch Forum
Topic: ECHOing to a file without a trailing space
Replies: 6
Views: 20792

Re: ECHOing to a file without a trailing space

Code: Select all

(echo(%field1%;%field2%;%field3%;%field4%)>file4.tmp
by jeb
10 Nov 2023 12:28
Forum: DOS Batch Forum
Topic: space is added to the file if it is after the extension
Replies: 2
Views: 15072

Re: space is added to the file if is after the extension

Hi Saso, not quite strange, it's the expected behavior. The rule is: If a redirection to a stream is found, store it in a buffer (one buffer for each stream), remove the redirection text from the command line. What same mean? Some examples @echo off del /s test.txt 2> NUL > NUL @echo on echo Test1>>...
by jeb
18 Sep 2023 02:42
Forum: DOS Batch Forum
Topic: GOTO inside FOR loop ? Can it be done ?
Replies: 3
Views: 3226

Re: GOTO inside FOR loop ? Can it be done ?

As you have already observed, GOTO breaks any loop, it can't be used for continue, but for break. For CONTINUE, in most cases I would recommend an IF block instead. FOR /L (1 1 10) DO ( if someCondition ( echo DoWork ) ELSE ( DoNothing ) ) If your code is very complex/long you could use GOTO's for t...
by jeb
15 Sep 2023 08:49
Forum: DOS Batch Forum
Topic: where that space come from?
Replies: 3
Views: 6634

Re: where that space come from?

It's always a good idea to use the safe SET-Syntax.
This is safe against trailing white spaces and additionally it avoid problems with special characters

Code: Select all

set "sch_1=%~5"
by jeb
23 Aug 2023 02:27
Forum: DOS Batch Forum
Topic: avoid trailing space when piping to CLIP [SOLVED]
Replies: 6
Views: 5449

Re: avoid trailing space when piping to CLIP

The extra space is indirectly generated by the pipe operation. To use the pipe, cmd.exe converts the expressions on both sides. Obviously this is hard to debug, but with the magic cmdcmdline variable it can be done. @echo off ( echo This is echo a test echo %%cmdcmdline%% <nul set /p .=Output) | fin...
by jeb
14 Aug 2023 05:14
Forum: DOS Batch Forum
Topic: Sanitization of carets/exclamation marks inside a macro
Replies: 11
Views: 10243

Re: Sanitization of carets/exclamation marks inside a macro

Okay, I shouldn't write when I'm tired :?

I completely missed the ELSE part of your code.
Your definition looks simpler and better than mine, I don't know why I didn't found it myself
by jeb
10 Aug 2023 02:52
Forum: DOS Batch Forum
Topic: Sanitization of carets/exclamation marks inside a macro
Replies: 11
Views: 10243

Re: Sanitization of carets/exclamation marks inside a macro

Shouldn't the following work just fine, then? If the only requirement is that the parser has to stop on the first character after the empty line, then & fits this requirement perfectly: if "%=^%=" == "%=%=" ( set ^"\p=%%<nul" set ^"\n=^^^ %= These lines are supposed to be undented and empty; =% %= ...
by jeb
08 Aug 2023 04:43
Forum: DOS Batch Forum
Topic: Sanitization of carets/exclamation marks inside a macro
Replies: 11
Views: 10243

Re: Sanitization of carets/exclamation marks inside a macro

This should work IF "" == "%$for:param=3%" echo arg3 is empty You test against command line arguments, but you should test against macro FOR-Parameters instead, there the %%3 is a safe parameter. But my set "\n=^" definition for the command line context is weak, it doesn't support multi line blocks ...
by jeb
07 Aug 2023 10:10
Forum: DOS Batch Forum
Topic: Sanitization of carets/exclamation marks inside a macro
Replies: 11
Views: 10243

Re: Sanitization of carets/exclamation marks inside a macro

Regarding the definition - actually I've took it straight out of your library - I also can't think of anything that would incline user input. (It doesn't hurt to have it, though...?) I criticized my own code, that's hard :D The <NUL doesn't harm, but it's still superfluous . Notably I find a need t...
by jeb
06 Aug 2023 01:48
Forum: DOS Batch Forum
Topic: Sanitization of carets/exclamation marks inside a macro
Replies: 11
Views: 10243

Re: Sanitization of carets/exclamation marks inside a macro

I've just whipped up a macro to do exactly that (taking ideas from your repo yet again, lol): I am glad to hear that someone is looking at my library at all :D Actually, instead of double percent expansion, could replacement syntax work? Similar to what you've done with for-parameters in your libra...
by jeb
04 Aug 2023 02:07
Forum: DOS Batch Forum
Topic: Sanitization of carets/exclamation marks inside a macro
Replies: 11
Views: 10243

Re: Sanitization of carets/exclamation marks inside a macro

It's stupid simple :D The problem is the CALL not your function. call echo #1 ^^ call echo #2 ^^^^ call echo #3 "^^" call echo #4 "^^^^" call call echo #5 "^^^^" call call call echo #6 "^^^^" #1 ^ #2 ^^ #3 "^^^^" #4 "^^^^^^^^" #5 "^^^^^^^^^^^^^^^^" #6 "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" It's tricky t...
by jeb
29 Jun 2023 01:55
Forum: DOS Batch Forum
Topic: Timeout not working in file-works in command line
Replies: 2
Views: 2056

Re: Timeout not working in file-works in command line

Hi dtmenges,

I guess you called your batch file "timeout.bat"?
Think a bit about the name
by jeb
21 Jun 2023 15:44
Forum: DOS Batch Forum
Topic: Reinterpreting macros in command-line context
Replies: 9
Views: 3478

Re: Reinterpreting macros in command-line context

jeb wrote: ↑ Wed Jun 21, 2023 10:53 am "CALL SET" is a substitute for DisableDelayedExpansion, but my reason for using it is quite different! To replace an exclamation mark, the only way is to use the percent replace syntax, but as we are already in a code block, percent expansion doesn't work, so ...
by jeb
21 Jun 2023 11:31
Forum: DOS Batch Forum
Topic: User defined prompt with dynamic data
Replies: 8
Views: 3493

Re: User defined prompt with dynamic data

I reviewed the ANSI escape codes and found no way to generate an ENTER char. Indeed, there is no way to generate nothing other than the cursor position You look at the wrong site, I found at least ESC Z Send VT100 Identification String ESC [ c Send VT100 Identification String ESC [ x (V) Send Termi...