Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1289
  • Last Modified:

batch files

do you know how to continue issuing commands in a  .bat file once you are off the c:\ (or d:\ e:\ etc) prompt?

for instance, if i use nslookup <return> in my batch file I get the > prompt then my batch file dies. is there a way to continue?
0
bhehir
Asked:
bhehir
  • 12
  • 8
  • 2
  • +6
1 Solution
 
Dufo G. BelskiRetired bureaucrat/desktop supportCommented:
I'm a little unclear here, but if you want to branch out from a batch file to run other tasks, you should create another batch file to run the task (say nslookup) and call it from your original batch.

For example, nslookup.bat contains whatever command is necessary to run nslookup.

Then in your main batch file you'd show

stuff
stuff
more stuff
call nslookup.bat
more stuff
more stuff.

This passes control to the second batch, and returns control when it's done.

0
 
bhehirAuthor Commented:
maybe this will make more sense....

first step in batch file is this..
c:\ nslookup

which produces this output

Default Server:  x.x.x.x
Address:  x.x.x.x

>

this is where i die.. i can't get anything to go after the > prompt appears

does that make sense? this is true even i call another batch file at that point in the script...
0
 
tonnybrandtCommented:
I made a small test and here is the output from my little test.bat that calls lookup.bat, just as you have done in your example above:
---------------------------------------------------------
E:\>echo 3
3

E:\>call lookup.bat

E:\>nslookup
Default Server:  ns.tele.dk
Address:  193.162.159.194

www.hotmail.com  <----- i typed this
Server:  ns.tele.dk
Address:  193.162.159.194

Non-authoritative answer:
Name:    www.hotmail.com
Addresses:  64.4.52.7, 64.4.53.7, 64.4.54.7, 64.4.43.7
          64.4.44.7, 64.4.45.7

> exit <------ i typed this

E:\>echo 4
4
---------------------------------------------------------
Does this answer you question ?.

Hope this helps
Tonny
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
tonnybrandtCommented:
Oh.. And here are the batfiles:

E:\>type test.bat
echo 1
echo 2
echo 3
call lookup.bat
echo 4

E:\>type lookup.bat
nslookup
0
 
Henry_KumagaiCommented:
Nslookup requires input from the user.  I don't think there is a way to for it to get data from another text file.

of course, if you already know the IP address or name you want to resolve, then you say in your batchfile:

c:>nslookup 207.46.230.219

or...

c:>nslookup yahoo.com

That will get you output and return you to a DOS prompt.  Actually, now that I'm getting my thinking going, I suppose to you could assign variables from text files and such and say:

c:>nslookup %ip_address%
REM (will this work???)

Before I confuse you further, what is your ultimate goal here?  That might be a better way to solve your problem.  What are you trying to get your .bat to do?
0
 
czpczpCommented:
You can echo "exit" on the same line preceeding the NSLookup command.


Just do:


echo.exit |nslookup



This will exit past ">" and bring you back to a command prompt.


BTW, the character before nslookup is the pipe char created by pressing shift-backslash.
0
 
czpczpCommented:
Even using "Echo.|" w/o "exit" will give you your desired output and return you to a command prompt.


<eg>

echo.|nslookup
0
 
czpczpCommented:
Still another way that's really not as clean as my first two suggestions is to create a single line text file containing the word "exit" (w/o the quotes) and directing it to NSLookup.


<eg>
nslookup < exit.txt
0
 
bhehirAuthor Commented:
i have been a little bit too ambiguos..

i am trying to script a SQLNET connection, a few queries outputting to text files, and exiting back to the command prompt.. the problem is that i cant get any input once i make the SQL connection and see the SQL> prompt.. the whole point of the script is to schedule it to run on off hours through the AT command, so I cannot type anything...

the ? boils down to whether user input to the SQL> prompt (just like the > prompt after typing in NSLOOKUP) can be automated
0
 
bhehirAuthor Commented:
i have been a little bit too ambiguos..

i am trying to script a SQLNET connection, a few queries outputting to text files, and exiting back to the command prompt.. the problem is that i cant get any input once i make the SQL connection and see the SQL> prompt.. the whole point of the script is to schedule it to run on off hours through the AT command, so I cannot type anything...

the ? boils down to whether user input to the SQL> prompt (just like the > prompt after typing in NSLOOKUP) can be automated
0
 
czpczpCommented:
Do the following to the nslookup line AND include ONE "echo." on the very next line:

echo.exit |nslookup
echo.



Going back to your other comment ">this is where i die.. i can't get anything to go after the > prompt appears", this will get past that for you.  Please provide more info if this is not what you're looking for.
0
 
bhehirAuthor Commented:
this last comment is moving in the right direction - i can get back to the command prompt now.. but how do i script information to input after nslookup command (i.e www.experts-exchange.com) and not just exit to a command prompt?
0
 
bhehirAuthor Commented:
this last comment is moving in the right direction - i can get back to the command prompt now.. but how do i script information to input after nslookup command (i.e www.experts-exchange.com) and not just exit to a command prompt?
0
 
czpczpCommented:
That's great that "echo.exit|" worked for you but can you please elaborate on your last question.  I don't quite understand.


>> but how do i script information to input after nslookup command (i.e www.experts-exchange.com) and not just exit to a command prompt?  


I don't know what you mean by "how do i script information to input after nslookup command".
0
 
bhehirAuthor Commented:
this last comment is moving in the right direction - i can get back to the command prompt now.. but how do i script information to input after nslookup command (i.e www.experts-exchange.com) and not just exit to a command prompt?
0
 
bhehirAuthor Commented:
here goes...

in my script, if i use

echo.exit |nslookup
echo

i don't get any information.. all that does for me is to allow me to type in nslookup and get back to a command prompt.. i want to type in nslookup, www.whatver.com, get the information, and then exit out.. but i want all of this scripted... your echo.exit|nslookup followed by an exit doesn't allow for me to type in a dns name

does that make sense?
0
 
bhehirAuthor Commented:
here goes...

in my script, if i use

echo.exit |nslookup
echo

i don't get any information.. all that does for me is to allow me to type in nslookup and get back to a command prompt.. i want to type in nslookup, www.whatver.com, get the information, and then exit out.. but i want all of this scripted... your echo.exit|nslookup followed by an exit doesn't allow for me to type in a dns name

does that make sense?
0
 
czpczpCommented:
You can put all of the addresses in one text file (i.e. DNS.txt) like this:


www.experts-exchange.com
www.Microsoft.com
207.208.125.32
www.Whatever.com
etc.


echo.exit |nslookup < DNS.txt
echo.



This will execute the lookup for *each* address.  You said that this had to work without user input since it's a scheduled job that runs at night.  I hope I'm on the right track for what you're after.
0
 
czpczpCommented:
You can also send the results of each address to a log file with something like this:


echo.exit |nslookup < DNS.txt >>LogResults.txt
echo.
0
 
GrizzleCommented:
Bhehir buddy,

be careful with that refresh button when you're posting comments OK, that's why you're getting all these double (and triple) ups.

Sorry I can't help with your question...

Grizzle
0
 
SunBowCommented:
done?  I assume now you go
> once you are off the c:\ (or d:\ e:\ etc) prompt?
= is meaningless here.

While I assume you have what you need, I encourage consideration of multiple approaches, namely, use of the CALL command from 1st comment, and the possibility for multiline commands like:

nslookup server1
nslookup server2

I am big on doing logs, so for development purposes, in .bat file before czpczp last echo, try on

Type LogResults.txt

Since you seem less familiar, a quick upspeed, the double >> does append. This way you lose nothing, from one log event to another. Comes in very very handy for tracking things you have that run auto when not around. Toss in some datestamps while at it. But,,, as-is, this grows forever. So prewarn you must needs delete it up front. One way, especially if hitting the logfile more than once, is to go
<command>    >LogResults.txt

Use the single angle bracket will (re)create the file for you, handling the delete/cleanup/noninteractive with a line that looks like the ones you use for appending.

For other programs, needing special handling, we used to run a program
KeyFake
right before the command needing input (such as nslookup)

It did as name implies, stuffing input buffer full of keystrokes that the following program would accept as input. Most common use was <CR>, <LF>, <ESC> and function keys.

czpczp,

Looks like yours is best fit. FWIW I validated this on Win2K. But as-is, there seems no need for the echo or echo. commands anymore, or am I missing something.
0
 
czpczpCommented:
SunBow, as you suspected, the extra "echo." is *not really* needed.  I just added it so that bhehir would actually be at a command prompt after the nslookup and before the next command is executed.  In either case, it doesn't really matter which way he does it.  It's just a little neater though especially if he's logging the results (using either ">>" append or ">" overwrite).  The following two batch's show what I mean.  The first one does not have the "echo." and the second one does.  (The output is the same for both NT4.0 and Y2K.)



@echo off
cls
echo 1
echo 2
echo.exit|nslookup
echo 3
echo 4


Produces:
------------
1
2
Default Server:  MySite.com
Address:  10.0.0.8

> 3
4





@echo off
cls
echo 1
echo 2
echo.exit|nslookup
echo.
echo 3
echo 4



Produces:
------------
1
2
Default Server:  MySite.com
Address:  10.0.0.8


3
4
0
 
SysExpertCommented:
Sounds good so far !
0
 
SunBowCommented:
bhehir, seems rather complete now, for closure, only thing left could be (?) does same script apply for a SQLNET connection, I cannot test.

[footnote]For others, who support multi OS, just remember the echo/dot may behave differently for older OS. Nice to see an implementation (czpczp) that makes good use of it. The NsLookup command may yet be 90% free Berkeley Unix code, but not as full featured in capabilities, so development of cross-platform tools for deployment may need a tweak or three.
0
 
czpczpCommented:
How 'bout using a deltree equivalent?  The following (NT specific) batch does what the 9x deltree command does using the same syntax (deltree DirName).

I created a blank directory which included many subdirectories (including blank ones) and files and the following batch wipes them all out.  Like you, I got the actual name of the "blank" directory by using "dir /x".


So using this batch, do:

deltree com1




rem  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  Deltree.BAT  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@echo off
cls


if /i %1$==$ goto :Missing
if not exist %1\. goto :NoDir %1


echo.
echo Are you sure you want to delete ALL the FILES within %1?
echo           ---------------------------------
echo    Press Any Key to Continue or CTL-Break to Abort
pause>nul

for /f "tokens=*" %%i in ('dir %1 /b /x /a-d') do del "%1\%%i"



echo.
echo.
echo Are you sure you want to remove all SUB-diretories from %1 ?,
echo            ---------------------------------
echo    Press Any Key to Continue or CTL-Break to Abort
pause>nul

for /f "tokens=*" %%a in ('dir %1 /b /x /ad') do rd /s /q "%1\%%a"


cls
echo.
echo                    Removing "%1"....
echo            ---------------------------------
echo    Press Any Key to Continue or CTL-Break to Abort
pause>nul
rd %1
cls
echo.
echo Complete !
goto end

:Missing
cls
echo.
echo.
echo Incorrect Syntax -- Use BatName (space) DirectoryName (i.e. Deltree Com1)
echo.
echo.
goto end


:NoDir
cls
echo.
echo.
echo Directory %1, does not Exist.
echo.
echo.

:end

rem  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  Deltree.BAT  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
 
czpczpCommented:
Gent's, please excuse my last post.  I inadvertently posted this comment here as opposed to the following thread -- my apologies.

It's was for:
http://experts-exchange.com/jsp/qShow.jsp?qid=20141758
0
 
MoondancerCommented:
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20137537.html
http://www.experts-exchange.com/questions/Q.20143014.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
czpczpCommented:
Whoa, this is STILL open (well, now pending delete).   I totally forgot about this one – I gotta visit EE more often.   IMO, I believe bhehir got his/her answer.   I’m surprised that he/she never closed nor responded to this thread considering his/her question history...
0
 
MoondancerCommented:
bhehir ->  Once comments have been added, we need to help you with the outcome of this question.  

Can you please tell me what you'd like us to do with this question?  If more than one expert helped you, I can help facilitate a point split.  

Listening further with thanks,
Moondancer - EE Moderator
0
 
czpczpCommented:
Wow, I’m surprised to have received an email notification about this!    I haven’t had too much time of late to visit EE much and forgot about the couple of old questions that were never closed that were emailed to me today.

bhehir's question was clearly answered.  Considering that it’s been 2 years since his or her’s last post, I don’t expect a response from bhehir.    Administrators, handle the question as you see fit and put this in PAQ.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 12
  • 8
  • 2
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now