Scripts Thread, How do I put Nslookup exit status into a variable! DelProf2.exe script in Coding and Web Development; I have a problem. I have wrote a script that gets an IP address from Nslookup and passes it to ...
-
9th October 2012, 11:22 AM #1
- Rep Power
- 0
How do I put Nslookup exit status into a variable! DelProf2.exe script
I have a problem. I have wrote a script that gets an IP address from Nslookup and passes it to DelProf2.exe.
However, I obviously need some error handling in the script so I can influence the flow of the batch file as it is run (if something goes wrong GOTO function name).
I'd like to control the flow upon Nslookup succeeding or failing.
How do I access the exit status and assign it to a variable?
Thanks in advance. This is my first post. This has been doing my head in!
Note: I will post up finished bat file upon completion so you can all benefit if needed.
Last edited by psutton00; 9th October 2012 at 02:26 PM.
-
-
IDG Tech News
-
9th October 2012, 02:55 PM #2
How do I access the exit status and assign it to a variable?
Microsoft chose not to include something as useful as an exit code for NSLOOKUP. What a disgrace.
Try this. It's very nasty code that uses a temp file but this code should do the trick nonetheless.
Code:
@echo off
nslookup DOMAIN_TO_TEST 2> %temp%\temp.txt
for /f "tokens=3 delims= " %%a in ('find /c /i "Non-existent domain" %temp%\temp.txt') do (
if %%a NEQ 0 (set Found=false) else (set Found=true)
)
if %found% == true (
echo The domain exists
) else (
echo The domain does not exist
)
Last edited by jinnantonnixx; 9th October 2012 at 03:00 PM.
-
-
9th October 2012, 03:16 PM #3
- Rep Power
- 0
Typical Microshite.
Thanks for the reply. I have been waiting all day!
Is there any way to use the FIND command to search the output in CMD rather than use a temp file?
-
-
9th October 2012, 03:19 PM #4
- Rep Power
- 0
I have tried piping with no avail.
-
-
9th October 2012, 03:23 PM #5 FIND isn't too clever, either, you'll be shocked to learn.
The trouble is that an error from NSLOOKUP is sent through a different stream which isn't handled correctly by piping to FIND. It just doesn't work, which is why I had to use a file. I chose to pipe the STDERR output (which is the "2>" bit) to a file then run FIND against that looking for a specific message.
Unless another 'geeker with a 3rd Dan in script-fu knows of a better way?
SS64 is an tremendous site for all your scripty requisites.
Command Redirection, Pipes | SS64.com
Last edited by jinnantonnixx; 9th October 2012 at 03:29 PM.
-
-
9th October 2012, 03:45 PM #6
- Rep Power
- 0
Basically we need some legal legislation to be implemented to hold programmers responsible for there code. IE. if they don't put a god damn exit status in there code they are shot!
I am a student on placement and it was one the first I learnt at A-Level! Never write a program that doesn't tell other programs it has ran successfully or failed!
-
-
9th October 2012, 03:46 PM #7
- Rep Power
- 0
I will give it a bash, no pun intended, and let you know. It may take a while as I am having to change a fair amount of my code to adjust. Thanks for your support.
Last edited by psutton00; 9th October 2012 at 03:47 PM.
Reason: Grammatical
-
-
9th October 2012, 03:55 PM #8 
Originally Posted by
psutton00
I will give it a bash, no pun intended, and let you know. It may take a while as I am having to change a fair amount of my code to adjust. Thanks for your support.
Just put the NSLOOKUP check routine it in another file and use a 'call' to treat it as a function. If you use a SET command to set the variables, then it's a way of getting values visible between script routines. Messy, but in this case DOS batch scripting is very primitive. I'd probably try it in Powershell. That said, I find Powershell frustrating as it's an object-oriented scripting langauge, but the syntax is verb-based, not object-based! Gah!
DOS Batch - Function Tutorial
Last edited by jinnantonnixx; 9th October 2012 at 04:01 PM.
-
SHARE: 
Similar Threads
-
By oalcock in forum Netbooks, PDA and Phones
Replies: 1
Last Post: 24th August 2010, 05:25 PM
-
By morganw in forum How do you do....it?
Replies: 9
Last Post: 29th July 2010, 01:51 PM
-
By beeswax in forum General Chat
Replies: 12
Last Post: 10th January 2006, 09:38 AM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules