I want to write a loop in Batch, the idea was written in C.
//------------------------
for(par0=0.1;par0<1;par0=par0+0.1) {
command1 par0 par1;
command2 par0 par2;
command3 par0 par3;
}
//------------------------
//the par is parameter for command
How to change it to Batch(I use NT), thanks!
Regards,
Davy
A good starting point is
FOR /?
In this case in particular
FOR /L %variable IN (start,step,end) DO command [command-parameters]
That is for the NT/2000/XP CMD.EXE line. You'll might need
subroutines for the call (depending on their nature). Then things can
get tricky. For some examples see e.g.
115380 Mar 30 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
A caveat: The answer above is for XP. Some features of XP CMD.EXE
are not present in NT.
For getting to know batches and scripts you might also find the
following further links of use
http://www.uwasa.fi/~ts/http/http2.html#cmdscript
http://www.uwasa.fi/~ts/http/http2.html#batch
news:alt.msdos.batch.nt
In the MS-DOS+Win../95/98/Me COMMAND.COM line, incidentally, the task
is very tricky. Those interested might find e.g. the examples in the
following of some use
3) Is it possible to nest for loops in batch files?
250909 Oct 12 2005 ftp://garbo.uwasa.fi/pc/link/tsbat.zip
tsbat.zip Useful MS-DOS batch files and tricks, T.Salmi
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
Hmmm...why do C programmers seem to believe that everyone reads C :)
Your question is probably better placed in the alt.msdos.batch.nt group, but
still...
Try using the
FOR/?|more
command from the DOS prompt for docco on FOR (the |MORE allows you to read
it page-by-page)
I'd suggest
for /L %%i in (1,1,9) do command1 0.%%i par1 & command2 0.%%i par2 &
command3 0.%%i par3
would do the job - WITHIN a batch file. If executed from the command line,
change each %% to %
Now if you want a batch file which you feed with your three parameters par1
par2 and par3 then
---- cprog.bat begins
@echo off
for /L %%i in (1,1,9) do command1 0.%%i %1 & command2 0.%%i %2 & command3
0.%%i %3
---- cprog.bat ends
which you would execute as
CPROG par1 par2 par3
(This assumes that the C-hieroglyphics you've posted means
FOR A in 0 to 0.9 step 0.1 .....)
HTH
...Bill
> Davy wrote:
> > for(par0=0.1;par0<1;par0=par0+0.1) {
> > command1 par0 par1;
> > command2 par0 par2;
> > command3 par0 par3;
> > How to change it to Batch(I use NT), thanks!
>
> A good starting point is
> FOR /?
> In this case in particular
> FOR /L %variable IN (start,step,end) DO command [command-parameters]
> That is for the NT/2000/XP CMD.EXE line. You'll might need
> subroutines for the call (depending on their nature). Then things can
> get tricky. For some examples see e.g.
>
> 115380 Mar 30 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
> tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
>
> A caveat: The answer above is for XP. Some features of XP CMD.EXE
> are not present in NT.
>
> For getting to know batches and scripts you might also find the
> following further links of use
> http://www.uwasa.fi/~ts/http/http2.html#cmdscript
> http://www.uwasa.fi/~ts/http/http2.html#batch
> news:alt.msdos.batch.nt
>
> In the MS-DOS+Win../95/98/Me COMMAND.COM line, incidentally, the task
> is very tricky. [...]
What's tricky about downloading 4DOS and using that instead of
COMMAND.COM? :)
> [...] Those interested might find e.g. the examples in the
> following of some use
>
> 3) Is it possible to nest for loops in batch files?
> 250909 Oct 12 2005 ftp://garbo.uwasa.fi/pc/link/tsbat.zip
> tsbat.zip Useful MS-DOS batch files and tricks, T.Salmi
Downloaded and to be looked at when I have enough time.
--
">> consider moving away from Front Page...."
">To what? Any suggestions?"
"Naked bungee-jumping. It's less humiliating <g>"
-- Matt Probert in alt.www.webmaster, March 20, 2005
You can use the (more elementary) FOR statement in NT
to achieve something similar. Note that (unlike Win2000)
you don't have SET /a(arithmetic) so the demo below merely
lists the (first decimal places) literally and calls the LOOP
each time. In the LOOP the digit(n) passed to it in %1 parameter
is expanded to 0.%1 = 0.n to achieve your non-integer result.
In the demo, the commands are ECHO/{demo}-ed in an inactive
form. Remove the ECHO/{demo} where shown to activate them:
Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
FOR %%J IN (1 2 3 4 5 6 7 8 9) DO CALL :LOOP %%J
GOTO :EOF
:LOOP
:: ECHO commands as a demo of loop
:: Note that counter is passed to loop as %1 parameter
:: Remove the ECHO/{demo} to activate commands
ECHO/{demo}command1 0.%1 par1
ECHO/{demo}command2 0.%1 par2
ECHO/{demo}command3 0.%1 par3
====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects
This screen capture shows operation. Remember to
remove the ECHO/{demo} to have the commands executed
instead of merely displayed to screen:
============Screen capture Windows 2000 simulated in Win95
C:\WORK>demo.bat
{demo}command1 0.1 par1
{demo}command2 0.1 par2
{demo}command3 0.1 par3
{demo}command1 0.2 par1
{demo}command2 0.2 par2
{demo}command3 0.2 par3
{demo}command1 0.3 par1
{demo}command2 0.3 par2
{demo}command3 0.3 par3
{demo}command1 0.4 par1
{demo}command2 0.4 par2
{demo}command3 0.4 par3
{demo}command1 0.5 par1
{demo}command2 0.5 par2
{demo}command3 0.5 par3
{demo}command1 0.6 par1
{demo}command2 0.6 par2
{demo}command3 0.6 par3
{demo}command1 0.7 par1
{demo}command2 0.7 par2
{demo}command3 0.7 par3
{demo}command1 0.8 par1
{demo}command2 0.8 par2
{demo}command3 0.8 par3
{demo}command1 0.9 par1
{demo}command2 0.9 par2
{demo}command3 0.9 par3
C:\WORK>
============End screen capture
--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
Header email is rarely checked. Contact us at http://www.allenware.com/
>>In the MS-DOS+Win../95/98/Me COMMAND.COM line, incidentally, the task
>>is very tricky. [...]
> What's tricky about downloading 4DOS and using that instead of
> COMMAND.COM? :)
That, as well alternatively utilizing other additional tools, definitely
is a good option to proceed. In the OP's case perhaps the method most
suitable would be GnuAWK. Not because I often use it myself, but in
this case detachedly because he is programing in C. The two are very
close each other, if not practically equivalent in many respects.
Anyway, 4DOS is free in the case of MS-DOS+Win../95/98/Me, but
not (yet?) in the case of NT/2000/XP. GAWK is free throughout the
gamut.
If a reader is interested in 4DOS, one central link is
http://www.4dos.info/
If one is interested in GAWK, under MS-DOS I would recommend
233923 Mar 25 1995 ftp://garbo.uwasa.fi/pc/unix/gawk2156.zip
gawk2156.zip GNU awk text scanning and processing language
For the NT/2000/XP I would suggest getting
878915 2003-10-25 13:19 ftp://garbo.uwasa.fi/win95/unix/UnxUpdates.zip
UnxUpdates.zip Updates for UnxUtils GNU utilities for native Win32
I know it is a sensitive issue, so please anyone do not now take this
the wrong way. The OP would probably find it very useful to peruse
also the NT/2000/XP newsgroup, including its old postings available
e.g. at http://groups-beta.google.com/group/alt.msdos.batch.nt
>
> You can use the (more elementary) FOR statement in NT
> to achieve something similar. Note that (unlike Win2000)
> you don't have SET /a(arithmetic) ...
No, NT4.0 does indeed have 'set /a'.
--
Phil Robyn
Univ. of California, Berkeley
u n z i p m y a d d r e s s t o s e n d e - m a i l
Thanks for the pointer, Phil. With SET /a integer arithmetic
the loop can be made more general:
Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
:: Initialise integer loop variable
SET J=1
:LOOP
:: ECHO commands as a demo of loop
ECHO/{demo}command1 0.%J% par1
ECHO/{demo}command2 0.%J% par2
ECHO/{demo}command3 0.%J% par3
:: Bump J and test less than 10
SET /a J=%J%+1
IF %J% LSS 10 GOTO LOOP
====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects
This is preferable to my previous demo, since it's easily
extended to make far more loops.
In my view, Timo Salmi is right to point out that this is tricky in
Windows 95/98/ME (see below for comments on 4Dos).
The actual posted C loop can easily be handled with a simple
FOR 1 2 3 4 5 6 7 8 9 loop and a Subroutine recall in Windows
95/98/ME along the lines of the first example I posted.
However, the more general case of looping (even where the STEP is
simple, say a +/-power of ten), needs something like the DigitStop
deeply recursive FOR 1 2 3 4 5 6 7 8 9 loop. And it would be fair
to say many people find this tricky to follow, and to amend for
different START STEP STOP values. For example, to handle the
OPs problem in Windows 95/98/ME with a .01 step, from .01 to .99
this is the typical syntax:
Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 {Subroutine-Handler}
SET START=01
SET STOP=99
CALL %0 GOTO: _DGSTOP
SET COUNT=
GOTO EOF {=Subroutine-section-below=}
:_DGSTOP (Usage: CALL %0 GOTO: _DGSTOP)
IF (%STOP%)==() GOTO EOF
IF NOT ()==(%4) GOTO 1_DGSTOP
FOR %%D IN (0 1 2 3 4 5 6 7 8 9) DO CALL %0 GOTO: _DGSTOP %3 %%D
GOTO EOF
:1_DGSTOP
SET COUNT=%3%4
IF (%COUNT%)==(%START%) SET START=
IF NOT (%START%)==() GOTO EOF
:: ECHO commands as a demo of loop
ECHO/{demo}command1 0.%COUNT% par1
ECHO/{demo}command2 0.%COUNT% par2
ECHO/{demo}command3 0.%COUNT% par3
IF (%STOP%)==(%COUNT%) SET STOP=
:EOF {End-of-file}
====End cut-and-paste (omit this line)
For Win95/98/ME study/demo use. Cut-and-paste as plain-text Batch file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects
(repeat)Norman L. DeForest> > What's tricky about downloading 4DOS and using that instead of
(repeat)Norman L. DeForest> > COMMAND.COM? :)
As to 4Dos, now it's free, it's obviously attractive to Windows 95/98/ME
users. However your point would have been better made by:
(1) Showing a 4Dos solution
(2) Explaining how to install 4Dos without having to use it instead
of COMMAND.COM (in case someone preferring your solution doesn't
want to change any key components merely to solve one problem)
Presenting the 4Dos alternative as if it _requires_ replacing key
components (such as the command interpreter) makes the 4Dos
alternative seem less desirable - I assume that's not the intention.
Full details of where to get 4Dos and how to obtain our 4Dos Guide to
Installing it in Windows 95/98/ME without affecting any other operations
outside your Custom 4Dos window is available from the links in:
http://www.allenware.com/mcsw/bus.htm#ThirdParty
(Quoted from our 4Dos Guide):
You can read further installation information that will be useful
as you become more committed to 4Dos at Klaus Meinhard's Website:
http://www.4dos.info/4dinstfq.htm
TS> The OP would probably find it very useful to peruse
TS> also the NT/2000/XP newsgroup, including its old postings available
TS> e.g. at http://groups-beta.google.com/group/alt.msdos.batch.nt
...snip
Good suggestion, particularly since similar problems have come up in
alt.msdos.batch.nt - that's why I, too (via my UsualSuspects link),
suggested this:
"The NewsGroups microsoft.public.win2000.cmdprompt.admin and
alt.msdos.batch.nt specialise in detailed Windows NT/2000/XP discussions."
(quote from first item on UsualSuspects page)
> (1) Showing a 4Dos solution
How about the
DO (with several possible parameters, comparisons etc.)
some command(s)
ENDDO
command? It's the most versatile. Of course there's FOR, too, for those
who are more accustomed to that. GOSUB might be mentioned in this
context.
> (2) Explaining how to install 4Dos without having to use it instead
> of COMMAND.COM (in case someone preferring your solution doesn't
> want to change any key components merely to solve one problem)
See William's and my 4DOS installation articles, both available from my
http://www.4dos.info/4docs.htm page.
--
* Klaus Meinhard *
www.4dos.info
- 4DOS Info -
- Info for DOS -
>> What's tricky about downloading 4DOS and using that instead of
>> COMMAND.COM? :)
> That, as well alternatively utilizing other additional tools,
> definitely is a good option to proceed. In the OP's case perhaps the
> method most suitable would be GnuAWK. Not because I often use it
> myself, but in this case detachedly because he is programing in C.
> The two are very close each other, if not practically equivalent in
> many respects.
I might point out that this highlights exactly a point I have made in
the past:
solutions offered here tend to use no, if at all possible, or the
"smallest" possible external utility. This is undoubtfully a virtue from
one
point of view, or even an art. :-)
The result, however, if you try to use batch regularly, is that you need
another external proggy for the next problem, a third for the following,
and so on, until you have a whole directory full of differntly written
tools, all with different syntax, all with help of varying quality, and
all totally unintuitiv.
Installing 4DOS (and that means, in it's simplest version, nothing more
than putting the files in one dir and adding that dir to the path
statement) gives you hundreds of new commands, internal variables,
functions, especially for date and string manipulations, plus better
mostly everything else. You can write understandable code, without
nearly (see note) all of these external tools. So, for a power user, the
use of 4DOS is much more economic.
Note: External utils I use are better filters than those included in
MS-DOS: e.g. RPSORT. Buergh's LIST.COM I use regularly (though I have
written a amazingly capable replacement in 4DOS Batch), an ANSI driver
with better capabilties (I use ANSIPLUS). For extended text manipulation
a tool like AWK or SED might be better suited, though I have still to
come across a case I couldn't solve with 4DOS.
Sorry, couldn't resist ;-)
> Norman L. DeForest wrote:
> > On Sat, 16 Apr 2005, Timo Salmi wrote:
> >>Davy wrote:
> >>>for(par0=0.1;par0<1;par0=par0+0.1) {
> >>> command1 par0 par1;
> >>> command2 par0 par2;
> >>> command3 par0 par3;
>
> >>In the MS-DOS+Win../95/98/Me COMMAND.COM line, incidentally, the task
> >>is very tricky. [...]
>
> > What's tricky about downloading 4DOS and using that instead of
> > COMMAND.COM? :)
>
> That, as well alternatively utilizing other additional tools, definitely
> is a good option to proceed. In the OP's case perhaps the method most
> suitable would be GnuAWK. Not because I often use it myself, but in
> this case detachedly because he is programing in C. The two are very
> close each other, if not practically equivalent in many respects.
How different is GnuAWK from the version of awk (sorry, I have lost the
original zip file so don't know its filename) that has this in the
documentation (AWK.MAN)?
: AUTHOR
:
: Rob Duff, Vancouver, B.C., V5N 1Y9
: BBS: (604)877-7752 Fido: 1:153/713.0
:
: DATE
:
: 08-Feb-90
I have written a Never-Ending-September calendar routine that uses grep
and that version of awk in a batch file. (See sig and follow the 2nd URL
to grab a copy for yourself.)
>
> Anyway, 4DOS is free in the case of MS-DOS+Win../95/98/Me, but
> not (yet?) in the case of NT/2000/XP. GAWK is free throughout the
> gamut.
4NT is still shareware but, from what I have read, 4DOS can still be used
on NT/2000/XP for free. It just doesn't take advantage of all of the
Windows NT features or offer the same functionality as 4NT.
> If a reader is interested in 4DOS, one central link is
> http://www.4dos.info/
>
> If one is interested in GAWK, under MS-DOS I would recommend
> 233923 Mar 25 1995 ftp://garbo.uwasa.fi/pc/unix/gawk2156.zip
> gawk2156.zip GNU awk text scanning and processing language
[snip]
I'll have to try that one out and see how it differs from the version of
awk I currently have.
--
Norman De Forest http://www.chebucto.ns.ca/~af380/Profile.html
af...@chebucto.ns.ca [=||=] (A Speech Friendly Site)
My Usenet 2005 calendar: http://www.chebucto.ns.ca/~af380/Year-2005.txt
For explanation: http://www.chebucto.ns.ca/~af380/Links.Books.html#TandD
Does this work right? (borrowing from William).
@ECHO OFF
for /l %%a in (0,1,9) do (
for %%b in (1 2 3) do (
ECHO/{demo}command%%b 0.%%a par%%b
)
)
To do this as one line (minus the @echo off).
for /l %%a in (0,1,9) do for %%b in (1 2 3) do ECHO/{demo}command%%b
0.%%a par%%b
Thanks
Clay Calvert
CCal...@Wanguru.com
Replace "W" with "L"
(Snip)
> In the MS-DOS+Win../95/98/Me COMMAND.COM line, incidentally, the task
> is very tricky.
> --
> Prof. Timo Salmi
*** I may be misunderstanding this because I never learned C, but here
is the technique I use for having FOR-IN-DO run multiple commands:
IF "%1" == "*TASKS*" GOTO TASKS
FOR %%A IN ( whatever ) DO CALL 0% *TASKS* %%C
GOTO END
:TASKS
COMMAND 1 %2
COMMAND 2 %2
COMMAND 3 %2
:END
I believe this technique may have been pioneered by Kris Jamsa, but
don't quote me on that.
Apparently some newer versions of DOS allow one to run those commands
directly. 4DOS comes to mind. Does anyone know if DR-DOS 8 can do this, as
well?
Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/
> solutions offered here tend to use no, if at all possible, or the
> "smallest" possible external utility. This is undoubtfully a virtue from
> one point of view, or even an art. :-)
> The result, however, if you try to use batch regularly, is that you need
> another external proggy for the next problem, a third for the following,
> and so on, until you have a whole directory full of differntly written
> tools, all with different syntax, all with help of varying quality, and
> all totally unintuitiv.
(Snip "Installing 4DOS" information)
> Note: External utils I use are better filters than those included in
> MS-DOS: e.g. RPSORT. Buergh's LIST.COM I use regularly (though I have
> written a amazingly capable replacement in 4DOS Batch), an ANSI driver
> with better capabilties (I use ANSIPLUS). For extended text manipulation
> a tool like AWK or SED might be better suited, though I have still to
> come across a case I couldn't solve with 4DOS.
> Sorry, couldn't resist ;-)
> --
> * Klaus Meinhard *
*** No problem, Klaus. it seems to me that in the quest to perform
computer tasks, that we should make use of whatever can do the job. No one
system can do it all. I, and others, regularly advocate updated commands
such as XXCOPY and XSET. Others have recommend some of the UNIX
utilities which have been ported to DOS. 4DOS is an excellent update to
COMMAND.com and can solve a lot of problems.
Can much be solved with only the batch language which comes with DOS?
Yes. However, utilities and upgrades can make the job much easier and save
a lot of coding. If it's compatible with DOS, I think recommending
whatever we do gives more choices to a poster looking for a solution.
Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/
>>That, as well alternatively utilizing other additional tools,
>>definitely is a good option to proceed. In the OP's case perhaps the
>>method most suitable would be GnuAWK. Not because I often use it
>>myself, but in this case detachedly because he is programing in C.
> solutions offered here tend to use no, if at all possible, or the
> "smallest" possible external utility. This is undoubtfully a virtue from
> one point of view, or even an art. :-)
> The result, however, if you try to use batch regularly, is that you need
> another external proggy for the next problem, a third for the following,
> and so on, until you have a whole directory full of differntly written
It is a richness to have alternative solutions present with their pros
and cons. Personally, I've always been in favor of that kind of
diversity. It is better to have even too much than nothing.
It is obvious that there are some typical main lines adopted by the
regulars. These include e.g. (speaking now mainly of the
MS-DOS+Win../95/98/Me scene since CMD.EXE is more versatile.)
1) Pure batch. Sometimes too complicated or outright impossible,
though. One of the many masters of that approach is John Savage,
but he posts now very seldom.
2) Task-customized utilities, such as written by Kleebauer in asm
and by Stockton in TP. Both require intimate knowledge of the
programming language to write, but not to use. Difficulties may
arise if one is a system manager for a network of users. ASCII
distributuion coding has caused some discussion, but let's not
go there.
3) The 4DOS options. Usually sufficient for all upcoming tasks. You
have demonstrated that e.g. with your comparison to my MS-DOS
batch FAQ. In a network it may indeed be desirable to be able to set
it up without actually replacing COMMAND.COM.
4) AWK + SED which are very familiar to Unix users. Likewise, that's
all the additions one needs. The problem in a set of PCs is that one
must have the two available for all the relevant PCs.
5) QBASIC aided batches in the case of MS-DOS+Win../95/98/Me and WSH
aided scripts in the case of NT/2000/XP.
We all typically cover slightly different fields, which adds to the
users' options. Personally, I am by far best familiar with TP, even if I
don't use it much in here. AWK, SED, QBASIC, and WSH I use often to aid
my batches, but I am not a true specialist in any of those four.
Perhaps that about sums it up?
Since par1, par2, and par3 are undefined, but unlikely to be those
string literals, it would probably be better to use the original
separate line form for the commands.
--
T.E.D. (tda...@gearbox.maem.umr.edu)
>5) QBASIC aided batches in the case of MS-DOS+Win../95/98/Me and WSH
> aided scripts in the case of NT/2000/XP.
Just to note: WSH does not come with NT, however Qbasic is part of
every installation.
WSH is part of the default installation on Windows ME.
> (2) Explaining how to install 4Dos without having to use it instead
> of COMMAND.COM (in case someone preferring your solution doesn't
> Full details of where to get 4Dos and how to obtain our 4Dos Guide to
> Installing it in Windows 95/98/ME without affecting any other operations
> outside your Custom 4Dos window is available from the links in:
> http://www.allenware.com/mcsw/bus.htm#ThirdParty
Observations: The most important information is given, that is setting
up a separate 4DOS window. How about the additional, special case of
running a 4DOS batch within a COMMAND.COM window. That eventuality is
not covered? If appropriate, a separate note text file within
4dosguide.zip might be of interest to some of the users.
It is true that the information is given for 95/98/ME where long
file names are supported. However, given the rare 8+3 eventuality
4dosguide.zip however counts to 9+3.
There is already a note in the current version of our 4Dos Guide
about using 4Dos Batch files from the normal COMMAND.COM
prompt, including how to use a DosKey macro to simplify running
4Dos from a standard COMMAND.COM window:
******Quoted from current version of our 4Dos Guide
This example shows a Doskey macro in use to run a 4Dos Batch file
from the ordinary MS-DOS command prompt in Windows 95 (here we've
just loaded the DosKey macro temporarily, as a demonstration):
============Screen capture Windows 95
C:\WORK>type my4dosbatch.bat
@ECHO OFF
ECHO. Use 4Dos _ENV variable as follows
ECHO. Environment space left=%_ENV%
ECHO. Parameters passed were: %1 %2 %3 (and so on)
C:\WORK>doskey run4dos=C:\OTHER\4DOS\4DOS.COM /e:4096 /c $*
C:\WORK>run4dos my4dosbatch.bat one two three
Use 4Dos _ENV variable as follows
Environment space left=3732
Parameters passed were: one two three (and so on)
C:\WORK>
============End screen capture
Remember: use your chosen path where we've used the demonstration
path: C:\OTHER\4DOS\4DOS.COM
******End Quote
The Guide explains how to find the meaning of all the terms
used in the DosKey macro line.
> It is true that the information is given for 95/98/ME where long
> file names are supported. However, given the rare 8+3 eventuality
> 4dosguide.zip however counts to 9+3.
When you click on the link on our TroubleShooter page in a normal
browser you are offered the choice to save file to disk and you can
select any name you please as well as the folder. Any user who
doesn't wish to use the default name can type another in the File,
"Save as" dialogue.
You must be referring to every installation of NT as Qbasic is not part of
Windows 95/98/ME or XP installations. (I don't know about 2K or K3)
>
> WSH is part of the default installation on Windows ME.
FWIW, WSH was part of the default installation of Windows 98 and was
installed to Windows 95 with MSIE 4+ upgrade.
--
Todd Vargo (double "L" to reply by email)
> There is already a note in the current version of our 4Dos Guide
> about using 4Dos Batch files from the normal COMMAND.COM
> prompt, including how to use a DosKey macro to simplify running
> 4Dos from a standard COMMAND.COM window:
The "Notes item (e)". Understood. My point here is that it might be more
obvious to some readers if presented, perhaps more separately, in the
above terms. Now it is presented as "increasing one's [subsequent]
[4DOS] commitment". Completely up to you, but as constructively meant
reader's feedback this was to suggest perhaps presenting it
(alternatively) as "running 4DOS in the standard COMMAND.COM window".
Some potential users might even wish start from that option instead of
first graduating up from the main instruction's principal 4DOS separate
box option. (The 4DOS box option being very clearly instructed.)
>>4dosguide.zip however counts to 9+3.
> select any name you please as well as the folder. Any user who
> doesn't wish to use the default name can type another in the File,
> "Save as" dialogue.
Yes, that one is an "of course". But it means that the situation
can arise. (Coming from my MS-DOS archive site maintainer's experience.)
>On Sat, 16 Apr 2005 18:00:18 +0300, Timo Salmi <t...@uwasa.fi> wrote:
>
>>5) QBASIC aided batches in the case of MS-DOS+Win../95/98/Me and WSH
>> aided scripts in the case of NT/2000/XP.
>
>Just to note: WSH does not come with NT, however Qbasic is part of
>every installation.
NT does come with WSH 1.0. Sorry about that.
Thanks Clay.
Yes, a point well made. Added to "changes to make" list for next time
the Guide goes through change control. That note needs rewriting as
a Section in its own right, and flagged from the top of the Guide.
--
William Allen
> Perhaps that about sums it up?
Yes. No doubt others will chime in, but that's a resumé I can fully
agree with :-)
> Yes, a point well made. Added to "changes to make" list for next time
> the Guide goes through change control. That note needs rewriting as
> a Section in its own right, and flagged from the top of the Guide.
The DOSKEY approach is a good one. There might also be an alternative
way. That is putting it all, without the DOSKEY definition into a
COMMAND.COM batch file to be then run with 4DOS. I have the feeling that
at least the same recursive method should apply as I (and many others)
have used e.g. for QBASIC and GAWK aided COMMAND.COM batches. Perhaps
I'll tinker with it, time allowing, sometime in the future and consider
a complementary TSBAT FAQ item
165) How do I make my COMMAND.COM batch run with 4DOS stand-alone?
> Yes, a point well made. Added to "changes to make" list for next time
> the Guide goes through change control. That note needs rewriting as
> a Section in its own right, and flagged from the top of the Guide.
Let's not forget the simplest method: Install 4DOS in a separate
directory (not really essential, but it keeps things orderly. You could
choose any other dir in your path and forget about the next step.), add
that directory's name to the path statement, and then (after rebooting)
you can simply type 4DOS at any prompt and you will be in 4DOS :-) Type
exit to return to command.com prompt.
To start a 4DOS batch from command.com start 4DOS with the b atch name
and path, e.g.
4DOS /C c:\belfry\mybatch
You can even set an exit code that can be read from command.com as
errorlevel
If you are referring to a *.exe file, it must have been deleted from my
Windows 98 PC before it was given to me or must have never been installed.
I can't even find it in the *.CAB files in the C:\WIN98 directory:
I can find no wsh.exe file on my machine. I can find associated files
(*.dll, *.vxd, etc.) but no executable by that name. A grep for
"[Ww][Ss][Hh]" in my listing of *.CAB contents finds six entries:
DRIVER12.CAB:
mwshdw.dll Application Extension 14752 2002-04-17 10:22:15 AM 14752 100 FFFFFF
DRIVER20.CAB:
mwshdw.mws MWS File 26304 2002-04-17 10:25:00 AM 26304 100 FFFFFF
NET10.CAB:
wshtcp.vxd Virtual device driver 9917 2002-04-17 10:25:47 AM 9917 100 FFFFFF
PRECOPY2.CAB:
wsh.inf Setup Information 10528 2002-04-17 10:27:06 AM 10528 100 FFFFFF
WIN98_59.CAB:
wshext.dll Application Extension 73728 2002-04-17 10:48:17 AM 73728 100 FFFFFF
WIN98_63.CAB:
wshom.ocx OCX File 132368 2002-04-17 10:49:18 AM 132368 100 FFFFFF
Because of the WSH vulnerabilities I have heard about being exploited by
trojans and worms, I'm not even sure if I would want it on my machine.
What could I do with it that couldn't be done with an appropriate batch
file and a DOS utility (from elsewhere or written by myself) or a
GW-BASIC routine?
--
">> consider moving away from Front Page...."
">To what? Any suggestions?"
"Naked bungee-jumping. It's less humiliating <g>"
-- Matt Probert in alt.www.webmaster, March 20, 2005
William,
> (2) Once the 4dos.com component is itself downloaded, the Batch
> file recalls itself in a 4dos.com /c child shell to complete the
> installation using 4Dos syntax to ask the user various questions
> about where and how he/she wants the files located.
for a few ideas what is possible in a 4dos installation script take a
look at the 4XBTM installation batch. 4XBTM is the name of my old 4DOS
batch collection available at my site (see sig).
> On Sat, 16 Apr 2005, Todd Vargo wrote:
>
>> FWIW, WSH was part of the default installation of Windows 98 and was
>> installed to Windows 95 with MSIE 4+ upgrade.
> If you are referring to a *.exe file, it must have been deleted from my
> Windows 98 PC before it was given to me or must have never been installed.
> I can't even find it in the *.CAB files in the C:\WIN98 directory:
cscript.exe and wscript.exe
> > There is already a note in the current version of our 4Dos Guide
> > about using 4Dos Batch files from the normal COMMAND.COM
> > prompt, including how to use a DosKey macro to simplify running
> > 4Dos from a standard COMMAND.COM window:
> The "Notes item (e)". Understood. My point here is that it might be more
> obvious to some readers if presented, perhaps more separately, in the
> above terms. Now it is presented as "increasing one's [subsequent]
> [4DOS] commitment". Completely up to you, but as constructively meant
> reader's feedback this was to suggest perhaps presenting it
> (alternatively) as "running 4DOS in the standard COMMAND.COM window".
> Some potential users might even wish start from that option instead of
> first graduating up from the main instruction's principal 4DOS separate
> box option.
>--
> Prof. Timo Salmi
*** I have done this. I wrote a short batch file which is similar to
William's DOSKEY macro back when I had NDOS. I have switched to 4DOS,
now. The batch file runs 4DOS as a secondary shell, completes the task,
and exits to COMMAND.com. This allows me to have the features of 4DOS but
without disrupting the COMMAND.com setup. Unfortunately, there is a slight
delay when using this method.
I will eventually switch this so that 4DOS is the primary and
COMMAND.com is the secondary. However, it will mean a lot of re-writing
of many batch files first. )-:
Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/
As foxidrive points out, cscript.exe and wscript.exe are the host engines of
the VBScript and JScript languages.
cscript.exe is the host engine for command line use.
wscript.exe is used by default and while it can be used from the command
line, it's purpose is for when a batch is not needed.
> Because of the WSH vulnerabilities I have heard about being exploited by
> trojans and worms, I'm not even sure if I would want it on my machine.
No problem, readers objecting to WSH use can simply pass on any suggested
code that uses it, or if they have already removed it from their machines.
The point is, since WSH is already installed on default installations of
Win98 and newer, why not teach people to make good use of it. There have
been suggestions in WSH groups for keeping it away from the hands of malware
engineers but I'll leave the details of that to the WSH groups to explain.
>
> What could I do with it that couldn't be done with an appropriate batch
> file and a DOS utility (from elsewhere or written by myself) or a
> GW-BASIC routine?
I do not suggest you replace your existing utilities or batch files with
WSH, rather, compliment what you already know with it. For those who have no
prior knowledge of GW-BASIC (or DOS utilities), WSH is a better suggestion
for newcomers to begin learning because it handles file and string
manipulation, LFN's, and the registry intrinsically, and it's already
installed in most cases.
> When you click on the link on our TroubleShooter page in a normal
> browser you are offered the choice to save file to disk and you can
> select any name you please as well as the folder. Any user who
Let me still elaborate on this of my comments. What you say works under
long-name supporting systems, which of course is crucial. However,
problems will be caused on unzipping on very old systems because
_within_ the package there is a 9+3 filename 4dosguide.txt. No big deal,
but that, rather than the actual package name will be a problem on the
very old systems. E.g. the old SHEZ archiver shell would fail to extract
that particular file. Even in this day and age someone might wish to
enhance his/her straight MS-DOS.
>>Some potential users might even wish start from that option instead of
>>first graduating up from the main instruction's principal 4DOS separate
>>box option.
> *** I have done this. I wrote a short batch file which is similar to
> William's DOSKEY macro back when I had NDOS. I have switched to 4DOS,
> now. The batch file runs 4DOS as a secondary shell, completes the task,
> and exits to COMMAND.com. This allows me to have the features of 4DOS but
> without disrupting the COMMAND.com setup. Unfortunately, there is a slight
> delay when using this method.
I already set up a 4dos box on a W95. That turned out to be very easy to
do, mostly along the lines provided by William Allen and Klaus Meinhard.
I did some tweaking of my own, though, in setting it up. In calling 4dos
I included in the desktop item properties a batch file to customize the
contents of the window. Most importantly I use ANSI to change the screen
colors, since my old W95 monitor is too dim for the default colors. I
prefer bright yellow or similar to see properly. It also allows This is
an idea which I have used since many years back in the W95 command.com
dosbox. Probably that is not the only way, but I have not looked at 4DOS
further options yet.
It will be interesting to experiment further, in particular to hopefully
arrive at a
165) How do I write 4DOS-aided batch files under COMMAND.COM?
Your feedback and the earlier information provided tells that it is
feasible. It also well befits the general idea of batch programming.
Create text file called DEMO.VBS which contains one line of text:
WScript.Echo WScript.Version
Look at the file in Windows Explorer. If it has an icon that looks
like a green S-shaped scroll of paper with lines across it on a
white background, then you have WSH installed. Double-click
the file in Explorer and a pop-up box will tell you what version
of WSH you currently have
The key executables for WSH are:
(1) GUI use: WSCRIPT.EXE (ECHO-s output to a pop-up box)
(2) Command line use: CSCRIPT.EXE (ECHO-s output to STDOUT)
Windows Script Host full details: http://msdn.microsoft.com/scripting/
165. How do I write 4DOS-aided batch files in a COMMAND.COM window?
The following batch demonstrates how to run 4DOS-aided batches in
conventional MS-DOS or in a COMMAND.COM based dosbox without
replacing COMMAND.COM with 4DOS.COM as the system's command
processor. This gives added flexibility for the quite limited
capabilities of COMMAND.COM in the same way as Gnu(AWK), SED, or
QBASIC can be used to enhance the lagacy batch solutions.
@echo off
::
:: Point to 4DOS
set fourpath=L:\4DOSHOME
set path_=%path%
if not exist %fourpath%\4dos.com goto _nofind4
set path=%fourpath%;%path%
::
:: Demonstrate building and running a 4DOS batch in a command.com window
:: Build (very simple, but requires 4DOS)
> %temp%\4temp.btm echo @echo off
>> %temp%\4temp.btm echo echo Demonstrating a 4DOS directory listing
>> %temp%\4temp.btm echo dir /2 /k /b %fourpath%
>> %temp%\4temp.btm echo.
>> %temp%\4temp.btm echo echo Demonstrating 4DOS function evaluation
>> %temp%\4temp.btm echo set i=%%@eval[4/7]
>> %temp%\4temp.btm echo echo %%i%%
:: Run
4dos /e:4096 /c %temp%\4temp.btm
:: Exit
goto _cleanup
::
:_nofind4
echo.
echo Exiting: 4DOS.COM is not available
echo.
echo You need to have the following files at %fourpath%
echo 4DOS.COM
echo 4DOS.HLP
echo 4DOS.ICO (optional)
echo 4HELP.EXE
echo Free from http://www.jpsoft.com/download.htm
goto _cleanup
::
:_cleanup
set path=%path_%
for %%f in (%temp%\4temp.btm) do if exist %%f del %%f
for %%v in (fourpath path_) do set %%v=
The output will be e.g.
D:\TEST>batfaq
Demonstrating a 4DOS directory listing
4DOS.COM 4DOS.HLP
4DOS.ICO 4DOS.ZIP
4DOSGUID.TXT 4DOSGUID.ZIP
4DREADME.TXT 4HELP.EXE
Demonstrating 4DOS function evaluation
0,5714285714
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful batch files and tricks ftp://garbo.uwasa.fi/pc/link/tsbat.zip
>I want to write a loop in Batch, the idea was written in C.
>//------------------------
>for(par0=0.1;par0<1;par0=par0+0.1) {
Since 0.1 cannot be represented exactly as a binary float, par) will not
be exactly 0.1 - 0.9 and in particular it may take a tenth value nearly
1.0 with that code. It is rarely wise to take floats as exact.
> command1 par0 par1;
> command2 par0 par2;
> command3 par0 par3;
>}
>//------------------------
>
>//the par is parameter for command
>
>How to change it to Batch(I use NT), thanks!
You should have used news:alt.msdos.batch.nt; this newsgroup was
created for DOS-compatible batch (now DOS..Win98/ME) whereas that
one was created for enhanced batch, and is used by a substantially
greater number of experts in your sort of operating system.
For loops with a simple arithmetic relationship relating the different
passes, it can be easy enough to unroll the loop, and to generate the loop
from parameterisable code. A moderately long intermediate file is not a
great disadvantage, and there is the benefit that one can readily see what
will happen when it runs.
echo.| COLS !9-1 | COLS ^1,1 | COLS 'command 1 * '0. 1 * 'par 1 ';
-> command1 0.1 par1;
command2 0.2 par2;
command3 0.3 par3;
command4 0.4 par4;
command5 0.5 par5;
command6 0.6 par6;
command7 0.7 par7;
command8 0.8 par8;
command9 0.9 par9;
Generate a line; for each line, generate 8 more; on each line, write a
number in column 1; for each line, generate a longer line using column 1
three times.
That is not limited to 9 lines, though for more one would do it a little
differently. COLS via below.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
> I expect we'll make the change when I rewrite the Guide note
> on COMMAND.COM DosKey use of 4Dos. For administrative
> reasons we'll probably make the 8.3 ZIPname reflect the version
> of the Guide, too. Thanks for making the further point about
> the internal name.
It would be much better IMO if you kept a consistent name to allow a
link to your guide without the need to constant updating.
IIRC you don't mention the advisabilty to use the .BTM extension for
4DOS batches. 4DOS at it's best with .BTM files (Batch To Memory - the
whole batch file is loaded into memory and executed, while command.com
loads only 1 line, executes it, loads the next line etc. This behaviour
is copied by 4DOS with batch files until told otherwise by the LOADBTM
command). It's easier on the user too: no frustration by trying to
execute a 4dos batch with lame command.com :-)
I am very happy to find many of you experimenting with 4DOS :-)
Some comments: you might want to take a look at the OPTION command's
possibilities (or the various 4DOS.INI directives, which are manipulated
whith OPTION):
> @echo off
To avoid the repetition of this line in every batch, set BATCHECHO=NO in
4DOS.INI or use the interactive OPTION - Configure - Options 1 page to
the same effect. 4DOS contains e very effective debugger which can be
invoked with a SETDOS /Y1 at the beginning (or any other place) of a
batch.
> set path=%fourpath%;%path%
Just a pointer to the ESET command: you can edit any var on the command
line with this.
> 4dos /e:4096 /c %temp%\4temp.btm
The size of the environment is much better set in 4DOS.INI
(ENVIRONMENT=nnnn, OPTION- Startup). See also the various UMB
directives: you can load nearly all of 4DOS into UMB if you have enough
free, so even a second shell (as you intend to use 4DOS) has enough of
the precious DOS memory.
HTH.
> properly. It also allows This is an idea which I have used since many
> years back in the W95 command.com dosbox. Probably that is not the
> only way, but I have not looked at 4DOS further options yet.
Sorry, I think somethings missing here or I am too dense. Could you
elaborate?
> Timo Salmi wrote:
>>properly. It also allows This is an idea which I have used since many
>>years back in the W95 command.com dosbox. Probably that is not the
>>only way, but I have not looked at 4DOS further options yet.
> Sorry, I think somethings missing here or I am too dense. Could you
> elaborate?
After posting the DRAFT 165 item my above comment is moot, and can thus
be skipped.