Batch file help request

L

Larry Dighera

Can you get this batch file to work? Put the text below in a file
named NSLOOKUP.BAT, and run it from a command prompt.

set /p userin=Enter IP address:
nslookup %userin%
pause

For some reason it loops back to the beginning and fails to display
the output from nslookup.exe. I've verified that the keyboard input
is being passed to nslookup.exe, but it's not clear that nslookup is
being executed. Clearly the pause statement is not.

This should be easy. I must be overlooking something simple.

OS: MS WindowsXP Home Edition.

(Please don't tell me this is not necessary because nslookup.exe
supports interactive use. It's become more important to make it work
than to actually use it.)

ADVthanksANCE
 
P

Pegasus \(MVP\)

What you observe is hardly surprising: You gave the batch
file the same name as the executable inside! Give the baby
a different name, and things will work out perfectly.
 
L

Larry Dighera

Many thanks for you assistance. Unfortunately changing the batch file
name has no effect on my system. When run, nslookup still fails to
produce output. But adding the extension '.exe' to the command did
make it work.

echo off
cls
set /p userin=Enter IP address:
nslookup.exe %userin% | findstr "Address Name ***" | find /v
"68.6.16.245"
pause

Thank you again for your help. I knew the issue was a simple
oversight.
 
P

Pegasus \(MVP\)

IMHO, leaving your batch file name as "nslookup.bat"
and referring to the executable as "nslookup.exe" is not
a sound decision. Sooner or later, the .exe extension
could get omitted and you or your successor will be
back to where you started. You might, for example,
type "nslookup" from the Command Prompt. Depending
on where you are and what your path looks like, you
might run the wrong command. Selecting a unique name
for your batch file would be a far more robust solution.

Your other problem may be just as easy to resolve,
perhaps by the addition of the /i switch to findstr.exe (which
again would make the batch file more robust!). If you post
the output from nslookup.exe then someone will be able
to help you. Depending on what exactly you're after, you
might want to simplify your command to:

nslookup.exe %userin% | find /i "Address"
 
L

Larry Dighera

IMHO, leaving your batch file name as "nslookup.bat"
and referring to the executable as "nslookup.exe" is not
a sound decision.

Agreed. I did change the batch file name as you suggested.
Your other problem may be just as easy to resolve,

I wasn't aware there was another problem. The *** is a literal
string, not a RE.
perhaps by the addition of the /i switch to findstr.exe (which
again would make the batch file more robust!).

/I Specifies that the search is not to be case-sensitive.

Findstr finds the lines I want as it is, but I understand what you're
saying.

I thought 'findstr' was a built in command, not an external program.
Interesting.
If you post
the output from nslookup.exe then someone will be able
to help you.

This is the nslookup.exe output when it succeeds:

C:\WINDOWS\system32>nslookup
Default Server: ns1.sb.sd.cox.net
Address: 68.6.16.245
dighera.com
Server: ns1.sb.sd.cox.net
Address: 68.6.16.245

Non-authoritative answer:
Name: dighera.com
Address: 67.19.91.163


This is the batch file output when nslookup.exe succeeds:

Enter IP address: dighera.com
Non-authoritative answer:
Name: dighera.com
Address: 67.19.91.163
Press any key to continue . . .



This is the nslookup.exe output when it fails:

C:\WINDOWS\system32>nslookup
Default Server: ns1.sb.sd.cox.net
Address: 68.6.16.245
Server: ns1.sb.sd.cox.net
Address: 68.6.16.245

*** ns1.sb.sd.cox.net can't find foo.foo: Non-existent domain
This is the batch file output when nslookup.exe fails:

Enter IP address: foo.foo
*** ns1.sb.sd.cox.net can't find foo.foo: Non-existent domain
Press any key to continue . . .
 
P

Pegasus \(MVP\)

See below.


Larry Dighera said:
Agreed. I did change the batch file name as you suggested.

*** Great!
I wasn't aware there was another problem. The *** is a literal
string, not a RE.


/I Specifies that the search is not to be case-sensitive.

Findstr finds the lines I want as it is, but I understand what you're saying.

I thought 'findstr' was a built in command, not an external program.
Interesting.

*** A command is "internal" if it is built into the Command
*** Processor cmd.exe. Internal commands do not require
*** an executable file. Examples: copy, del, cd. There is no
*** file called "copy.exe".
***
*** External commands require an executable file, e.g.
*** findstr.exe. I recommend that you verify this for yourself.
This is the nslookup.exe output when it succeeds:

C:\WINDOWS\system32>nslookup
Default Server: ns1.sb.sd.cox.net
Address: 68.6.16.245

Server: ns1.sb.sd.cox.net
Address: 68.6.16.245

Non-authoritative answer:
Name: dighera.com
Address: 67.19.91.163


This is the batch file output when nslookup.exe succeeds:

Enter IP address: dighera.com

*** Another misnomer. Your batch file prompts you
*** for an IP address, but "dighera.com" is a domain name,
*** not an IP address. Whom are you trying to mislead?
Non-authoritative answer:
Name: dighera.com
Address: 67.19.91.163
Press any key to continue . . .



This is the nslookup.exe output when it fails:

C:\WINDOWS\system32>nslookup
Default Server: ns1.sb.sd.cox.net
Address: 68.6.16.245

Server: ns1.sb.sd.cox.net
Address: 68.6.16.245

*** ns1.sb.sd.cox.net can't find foo.foo: Non-existent domain

This is the batch file output when nslookup.exe fails:

Enter IP address: foo.foo
*** ns1.sb.sd.cox.net can't find foo.foo: Non-existent domain
Press any key to continue . . .

*** Mmh. What exactly do you expect to happen when
*** you enter a domain name such as foo.foo that cannot
*** be resolved?

================================================================
 
L

Larry Dighera

:

[...]
Interesting.

*** A command is "internal" if it is built into the Command
*** Processor cmd.exe. Internal commands do not require
*** an executable file. Examples: copy, del, cd. There is no
*** file called "copy.exe".
***
*** External commands require an executable file, e.g.
*** findstr.exe. I recommend that you verify this for yourself.

I'm aware of that. What mislead me was the fact that 'findstr' was
included in the command.com '/help' output. I didn't realize that
external programs were included in the 'help' information of other
programs. I've never seen it done that way in UNIX.
*** Another misnomer. Your batch file prompts you
*** for an IP address, but "dighera.com" is a domain name,
*** not an IP address. Whom are you trying to mislead?

I'm not trying to mislead anyone; it's just a rather poorly thought
out expedient. Perhaps 'Enter a domain name or IP address' would be
more appropriate. What do you think?
*** Mmh. What exactly do you expect to happen when
*** you enter a domain name such as foo.foo that cannot
*** be resolved?

It was a simple way to intentionally force 'nslookup.exe' to output an
error message, so that I could filter and display it.

Thanks again for your interest and assistance.
 

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