CMD Files Number 2

D

Dond13

I started a new thread because the other one was so full I lost track of
where everything was. ED, I chose to go with your solution and it worked
with a minor change. I found my error with the SET command - I had spaces
between SET DRIVE = f: . When I took them out, it worked but only on the
first drive number entered. I reversed the order of the ERRORLEVEL check,
starting with 5 and working backward. Someone said the the compare was
"equal to or greater, so everything was always equal to or greater than 1
and it picked the first drive.

As I mentioned, I'm an old fart (almost 80) so my concentration leaves
something to be desired, but with your help, my problem is solved. I want
to thank everyone for their suggestions and I might be back again some day
when I try something new. I hope I never stop trying.

Thanks
Don D.
 
E

Ed Cryer

I started a new thread because the other one was so full I lost track of
where everything was. ED, I chose to go with your solution and it worked
with a minor change. I found my error with the SET command - I had
spaces between SET DRIVE = f: . When I took them out, it worked but only
on the first drive number entered. I reversed the order of the
ERRORLEVEL check, starting with 5 and working backward. Someone said the
the compare was "equal to or greater, so everything was always equal to
or greater than 1 and it picked the first drive.

As I mentioned, I'm an old fart (almost 80) so my concentration leaves
something to be desired, but with your help, my problem is solved. I
want to thank everyone for their suggestions and I might be back again
some day when I try something new. I hope I never stop trying.

Thanks
Don D.
Give us some more like this any time. We find out a lot from
experimenting. Just look at the people who've put time & effort into it;
and the successes they've had and problems they've found.

The problem with this Command Prompt over the many versions of Windows
is that it's so badly documented; and also varies from one Win to
another. Old programming languages such as COBOL or FORTRAN came well
documented; as do C++ or QBASIC today.

But I've seen enough here to teach me that there's a lot more potential
in this Win/DOS way of interfacing than I thought. Cmd can be called
from a simple Win icon, and you can input parameters through the DOS
screen; and it must be possible to take that to a much higher level so
that it almost becomes a GUI.

Ed
 
T

Thip

As I mentioned, I'm an old fart (almost 80) so my concentration leaves
something to be desired, but with your help, my problem is solved. I want
to thank everyone for their suggestions and I might be back again some day
when I try something new. I hope I never stop trying.

Thanks
Don D.
I'm 57 and can barely remember what I had for supper last night.

The cmd discussion thread was really fascinating. I remembered things I'd
forgotten ( ! ) and learned some new ones. Please don't stop trying.
 
J

Joe Morris

Ed Cryer said:
Dond13 wrote:
Give us some more like this any time. We find out a lot from
experimenting. Just look at the people who've put time & effort into it;
and the successes they've had and problems they've found.
The problem with this Command Prompt over the many versions of Windows is
that it's so badly documented; and also varies from one Win to another.
Old programming languages such as COBOL or FORTRAN came well documented;
as do C++ or QBASIC today.

But I've seen enough here to teach me that there's a lot more potential in
this Win/DOS way of interfacing than I thought. Cmd can be called from a
simple Win icon, and you can input parameters through the DOS screen; and
it must be possible to take that to a much higher level so that it almost
becomes a GUI.
If anyone is looking for printed documentation of the command line interface
executables, take a look at "The Microsoft Windows Command-Line
Administrator's Pocket Consultant 2nd edition" - by William Stanek,
Microsoft Press, list price $34.99, ISBN-13 9780735622623, available for
less online. Much of the material repeats what you can get in the help
output of the commands, but it's organized and indexed.

Be careful to get the second edition; some stores still shelve the first
edition (from 2004).

I keep a copy of the book at my desk in the office; it doesn't get used on a
daily basis but when something odd needs to be done and I can't recall the
exact syntax or whatever it's invaluable. I get good-natured ribbing about
my preference for using CMD-style scripts but my response is that I'm an
engineer: if it does what I need with no collateral damage, why not? (And
it worked quite nicely, thank you, when writing the scripts used to install,
harden, configure, and image Windows 7 systems, needing only a couple of
small POSH scripts and Windows apps to complete the build kit.)

Joe Morris
 
D

Dond13

Dond13 said:
I started a new thread because the other one was so full I lost track of
where everything was. ED, I chose to go with your solution and it worked
with a minor change. I found my error with the SET command - I had spaces
between SET DRIVE = f: . When I took them out, it worked but only on the
first drive number entered. I reversed the order of the ERRORLEVEL check,
starting with 5 and working backward. Someone said the the compare was
"equal to or greater, so everything was always equal to or greater than 1
and it picked the first drive.

As I mentioned, I'm an old fart (almost 80) so my concentration leaves
something to be desired, but with your help, my problem is solved. I want
to thank everyone for their suggestions and I might be back again some day
when I try something new. I hope I never stop trying.

Thanks
Don D.
One more quick question. While debugging my code, I put a 'PAUSE' in after
each command. This isolates exactly where a problem lies. Is there one
command that I could use at the beginning of a file that would create the
pause without having to enter it repeatedly. It seems logical that there
should be, but I can't find it in the list of commands
 
Z

Zaphod Beeblebrox

Dond13 said:
One more quick question. While debugging my code, I put a 'PAUSE'
in after each command. This isolates exactly where a problem lies.
Is there one command that I could use at the beginning of a file
that would create the pause without having to enter it repeatedly.
It seems logical that there should be, but I can't find it in the
list of commands
Not that I'm aware of. For troubleshooting a batch script I generally
don't turn echo off and put pause commands and echo statements before
the critical commands (or after, or both, depending). Yeah, bit of a
pain but it is what it is. With today's text editors and using
cut -n- paste it isn't too bad.
 
E

Ed Cryer

Not that I'm aware of. For troubleshooting a batch script I generally
don't turn echo off and put pause commands and echo statements before
the critical commands (or after, or both, depending). Yeah, bit of a
pain but it is what it is. With today's text editors and using
cut -n- paste it isn't too bad.

What do you think of this simple test harness?

@echo off
:top
if {%1} =={} goto :EOF
echo param={%1}
shift
goto :top

Just save it as "TestHarness.cmd" & try calling it manually directly
from the command line with various combinations of quotes, spaces, etc.
e.g.
Code:

C:>TestHarness.cmd abc def

I got it from;
http://boards.straightdope.com/sdmb/showthread.php?t=370519

Ed
 
D

Dond13

Zaphod Beeblebrox said:
Not that I'm aware of. For troubleshooting a batch script I generally
don't turn echo off and put pause commands and echo statements before the
critical commands (or after, or both, depending). Yeah, bit of a pain but
it is what it is. With today's text editors and using cut -n- paste it
isn't too bad.
I agree that it's not a major problem. I use the copy-n-paste and it makes
it pretty quick, but many compilers/assemblers usually have a feature to
step through code so I just thought there might be one that I was missing.

Thanks
Don D.
 
Z

Zaphod Beeblebrox

Ed Cryer said:
What do you think of this simple test harness?

@echo off
:top
if {%1} =={} goto :EOF
echo param={%1}
shift
goto :top

Just save it as "TestHarness.cmd" & try calling it manually directly
from the command line with various combinations of quotes, spaces,
etc.
e.g.
Code:

C:>TestHarness.cmd abc def

I got it from;
http://boards.straightdope.com/sdmb/showthread.php?t=370519
Looks nice, and from the syntax appears guaranteed to work in any
command prompt environment including "pure DOS"

Try this on for size as a one-liner:

@for %%i in (%*) do @echo [%%i]

I don't know if it works in "pure DOS" or in Win 9x command prompt
environments, but it sure is handy in NT+. You can put it at the
beginning of a batch file as a nice debug tool. Throw @echo %~f0 in
as another line at the start of a batch file and you get the full path
& file name of the batch in case there is any question what batch is
running.

--
Zaphod

Arthur Dent, speaking to Trillian about Zaphod:
"So, two heads is what does it for a girl?"
"...Anything else he's got two of?"
 
D

Dond13

Ed Cryer said:
SNIP

What do you think of this simple test harness?

@echo off
:top
if {%1} =={} goto :EOF
echo param={%1}
shift
goto :top

Just save it as "TestHarness.cmd" & try calling it manually directly from
the command line with various combinations of quotes, spaces, etc.
e.g.
Code:

C:>TestHarness.cmd abc def

I got it from;
http://boards.straightdope.com/sdmb/showthread.php?t=370519

Ed
I guess I'm dense. I don't understand what this would accomplish in
relation to stepping through a .CMD file execution. It looks like a
relatively closed loop until the parameters run out. How would this relate
to my .CMD file 'Restore'?

Don D.
 
Z

Zaphod Beeblebrox

Dond13 said:
I guess I'm dense. I don't understand what this would accomplish in
relation to stepping through a .CMD file execution.
Nope, you aren't dense, it doesn't relate except in the broad realm of
testing batch scripts.
It looks like a relatively closed loop until the parameters run out.
Indeed, it is.
How would this relate to my .CMD file 'Restore'?
It wouldn't, it seems we've gone off-topic a bit as is often the
case...

--
Zaphod

Arthur: All my life I've had this strange feeling that there's
something big and sinister going on in the world.
Slartibartfast: No, that's perfectly normal paranoia. Everyone in the
universe gets that.
 
E

Ed Cryer

I guess I'm dense. I don't understand what this would accomplish in
relation to stepping through a .CMD file execution. It looks like a
relatively closed loop until the parameters run out. How would this
relate to my .CMD file 'Restore'?

Don D.
An attempt to find some kind of all-embracing test harness within which
to run cmd files. I guess no one has one; probably not worth the effort
since no one writes lengthy ones.

A good test harness is invaluble in program writing; essential. I even
used one some years ago with ZX Spectrum machine code. It did all the
usual things, including stepping through so that you could follow the
path, and at any point you could see the contents of the registers &
variables.

Personally I wouldn't use the PAUSE after every line. I'd just leave
ECHO on. That should give you a sufficiently good trace of the path taken.

Ed
 
D

Dond13

Ed Cryer said:
An attempt to find some kind of all-embracing test harness within which to
run cmd files. I guess no one has one; probably not worth the effort since
no one writes lengthy ones.

A good test harness is invaluble in program writing; essential. I even
used one some years ago with ZX Spectrum machine code. It did all the
usual things, including stepping through so that you could follow the
path, and at any point you could see the contents of the registers &
variables.

Personally I wouldn't use the PAUSE after every line. I'd just leave ECHO
on. That should give you a sufficiently good trace of the path taken.

Ed
Thanks Ed. Maybe I'll find a use for it sometime but I was just confused
thinking that it would allow me to step through the Command file and
couldn't see how it related to what I was looking for. I have used several
tools in the past that allowed me to step through 'C ' code and a couple of
other languages. They are invaluable.

Thanks again

Don D
 
J

Joe Morris

Dond13 said:
One more quick question. While debugging my code, I put a 'PAUSE' in
after each command. This isolates exactly where a problem lies. Is there
one command that I could use at the beginning of a file that would create
the pause without having to enter it repeatedly. It seems logical that
there should be, but I can't find it in the list of commands
AFAIK not in any of the 32/64 bit Windows systems' CMD window, but in the
DOS foundation to Win9x (and presumably that abomination WinME) and MS-DOS
there was a switch to the COMMAND command that would step through a script
one line at a time, displaying each line and asking if it should be
executed.

H'mmm...let me find my junkbox virtual machines and fire them up...

For file "abc.bat" which contains two lines:
echo first
echo last

both Win98 and MS-DOS 6.22 offer the /y switch: command /y /c abc.bat

C:\>command /y /c abc.bat
abc.bat [Y/N]?Y

C:\>echo first
echo first [Y/N]?Y
first

C:\>echo last
echo last [Y/N]?Y
last

C:\>


Joe Morris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top