Search found 1620 matches

by Aacini
03 Jan 2012 22:12
Forum: DOS Batch Forum
Topic: Piped input and output to a batch file
Replies: 18
Views: 9257

Re: Piped input and output to a batch file

The Batch file below take the prefix and suffix from parameters 1 and 2. If the %3 parameter is given, then it is the name of the input file to process; otherwise the piped input is processed. Anyway, the output is always sent to the standard output (the screen) that is the way that a "filter p...
by Aacini
03 Jan 2012 21:39
Forum: DOS Batch Forum
Topic: Mechanics of reading a file with FOR /F
Replies: 11
Views: 3817

Re: Mechanics of reading a file with FOR /F

I had made some tests and conclude this point: FOR command always "process" all the values included in its set, that is, all the lines of a file with /F option, all the numbers of a loop with /L option, etc. However, if a GOTO or EXIT or a Batch file invocation with no CALL or CMD command ...
by Aacini
03 Jan 2012 21:08
Forum: DOS Batch Forum
Topic: "For" string needs to process only one line
Replies: 5
Views: 3146

Re: "For" string needs to process only one line

Let's do some clarifications: - If you want to process the first line of test.txt file , you may do it this way: set /P firstLine=< "%$file%" For example: for /F "tokens=1*" %%a in ("%firstline%") do ( ... - On the other hand, if you want to process the first line of th...
by Aacini
03 Jan 2012 20:38
Forum: DOS Batch Forum
Topic: Changing the PAUSE prompt
Replies: 5
Views: 5555

Re: Changing the PAUSE prompt

Just change your ECHO by SET /P =[message]< NUL

Code: Select all

SET /P =[message]< NUL
PAUSE > NUL

The < redirector indicate the command to take its input from the file instead the keyboard. NUL is the standard "empty" DOS file.
by Aacini
03 Jan 2012 20:16
Forum: DOS Batch Forum
Topic: create dir with text file in it
Replies: 3
Views: 1789

Re: create dir with text file in it

I think this Batch file do what you need: @echo off for /F "delims=" %%l in (aaa.txt) do ( if not exist "%%l" md "%%l" echo %%l > "%%l\%%l.dvd.disc" echo ^<discstub^>>> the_file.xml echo ^<message^>%%l is located in the DVD rack^</message^>>> the_file.xml echo...
by Aacini
03 Jan 2012 19:53
Forum: DOS Batch Forum
Topic: A dos version of unix which command
Replies: 13
Views: 5285

Re: A dos version of unix which command

I wrote this Batch file that seek for an executable file in the same order CMD.EXE do: @ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION REM CREATE A LIST OF FILE NAMES ADDING THE EXECUTABLE EXTENSIONS SET NAMEEXT=!PATHEXT:.=%1.! REM SEARCHES FILE NAMES IN CURRENT DIRECTORY, IF FOUND: ERRORLEVEL=1 FOR %%N I...
by Aacini
03 Jan 2012 19:38
Forum: DOS Batch Forum
Topic: SET/A: Macro to expand function results in SET /A expression
Replies: 4
Views: 6155

SET/A: Macro to expand function results in SET /A expression

3- Fractional (fixed point) operations using integer numbers. Arithmetic operations of SET /A command use 32-bits signed numbers with this range of values: -2147483648 to 2147483647. If a certain result requires less integer digits, the rest may be used for fractional part. To do that, just choose a...
by Aacini
30 Dec 2011 19:34
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 32
Views: 23972

Re: infinite loop with break condition

WHILE macro is simple to use because it resemble an original Batch command, like IF or FOR. However, it is slow when it is repeatedly executed because the complete while-body is created again each time it is executed. I slightly modified WHILE macro, and renamed it to WHILEBODY, so it just create th...
by Aacini
30 Dec 2011 15:37
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 32
Views: 23972

Re: infinite loop with break condition

I don't understand what is happening. :? Are you using Win XP? Perhaps someone may have another idea? :?
by Aacini
29 Dec 2011 20:55
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 32
Views: 23972

Re: infinite loop with break condition

I am posting again my complete WHILE macro test program: @echo off setlocal DisableDelayedExpansion set LF=^ ::Above 2 blank lines are required - do not remove set ^"\n=^^^%LF%%LF%^%LF%%LF%^^" set while=for %%n in (1 2) do if %%n==2 (%\n% call :StrLen argv argvLen=%\n% set "body=!argv...
by Aacini
29 Dec 2011 17:47
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 32
Views: 23972

Re: infinite loop with break condition

It looks good to me, I don't understand what can be wrong... :|

You may include ECHO's at several points to try to discover what the problem is.
by Aacini
29 Dec 2011 12:08
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 32
Views: 23972

Re: infinite loop with break condition

Thanks a lot Dave, it works now! set while=for %%n in (1 2) do if %%n==2 (%\n% call :StrLen argv argvLen=%\n% set "body=!argv:*do=!"%\n% call :StrLen body bodyLen=%\n% set /A condLen=argvLen-bodyLen-2%\n% for %%a in (!condLen!) do set "cond=!argv:~0,%%a!"%\n% echo for /L %%%%w in...
by Aacini
28 Dec 2011 22:02
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 32
Views: 23972

Re: infinite loop with break condition

I need the help of a Batch macro expert I tried to write a macro, called WHILE, to make good use of this trick in an easier way. I first wrote a subroutine that works ok. When I convert it to a macro I got an error in the line with the REM below: @echo off setlocal DisableDelayedExpansion set LF=^ :...
by Aacini
28 Dec 2011 16:31
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 32
Views: 23972

Re: infinite loop with break condition

You CAN get back a value. But only a single integer via errorlevel. Yes, it works! echo %\n% @echo off%\n% set num=0%\n% set result=0%\n% for /L %%%%i in (1,0,1) do (%\n% set /A num+=1%\n% if not %%1 %%2 %%3 call break !result!%\n% echo !num!%\n% set /A result+=num%\n% ) > while.bat echo exit %%1 >...
by Aacini
28 Dec 2011 13:39
Forum: DOS Batch Forum
Topic: infinite loop with break condition
Replies: 32
Views: 23972

Re: infinite loop with break condition

There is no way to break a FOR loop in the same CMD context , so I used a trick to export the cycle to a new CMD that can be broken via an EXIT command, and the execution return to the caller code: @echo off setlocal DisableDelayedExpansion set LF=^ ::Above 2 blank lines are required - do not remove...