?
Solved

windows batch file how can i get the DOS windows not to close

Posted on 2009-02-18
17
Medium Priority
?
765 Views
Last Modified: 2012-05-06
I am writing a basic batch file but the dos window closes when i am doen and i loose the output how can i prevent it from closing ?
0
Comment
Question by:kaos_theory
  • 7
  • 5
  • 2
  • +3
17 Comments
 
LVL 86

Expert Comment

by:oBdA
ID: 23674327
Either start it from a command window, or add a
pause
at the end of your script.
The former is better for testing, because you'll see what happens even if the script crashes.
0
 
LVL 2

Author Comment

by:kaos_theory
ID: 23674376
this is the scipt I have added the pause and it still closes

echo
set ORACLE_HOME=D:\Oracle\product\10GR2\db_1

cd %ORACLE_HOME%\Opatch

d:

opatch lsinventory

pause
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 23674413
is opatch another batch file. If so the batch file will transfer to there and never come back to the first.

If so call it with

@echo off
set oracle_home=:\Oracle\product\10GR2\db_1
cd /d %ORACLE_HOME%\Opatch
call opatch Isventory
pause

Steve
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 23674419
sorry typoed on your commandline bit of the call but you get the idea...
0
 
LVL 86

Expert Comment

by:oBdA
ID: 23674441
Works just fone for me here.
But again: for testing and debugging, run the batch from a command window. If a script crashes before the pause, the window will not stay open.
Open the window by running cmd.exe, change into the folder where the script is, run it from there.
0
 
LVL 2

Author Comment

by:kaos_theory
ID: 23674547
yeah i dont think that the opatch is a bat file , I am very neew at this kind of stuff , this opatch lsinventory is to see what oracle patches exist on a server , i see a opatch.bat in the directory but dont think it is what is being called or executed  

if i run this
@echo off
set oracle_home=:\Oracle\product\10GR2\db_1
D:
cd  %ORACLE_HOME%\Opatch

call opatch lsventory
pause

I GET THIS

The filename, directory name, or volume label syntax is incorrect.
'opatch' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . . .


THIS IS THE file structure of OPATCH

Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\Documents and Settings\Administrator>d:

D:\>cd D:\oracle\product\10GR2\db_1\OPatch

D:\oracle\product\10GR2\db_1\OPatch>dir
 Volume in drive D is New Volume
 Volume Serial Number is 9401-B814

 Directory of D:\oracle\product\10GR2\db_1\OPatch

10/16/2008  09:16 PM    <DIR>          .
10/16/2008  09:16 PM    <DIR>          ..
10/16/2008  09:16 PM    <DIR>          docs
01/06/2008  11:50 PM            19,263 emdpatch.pl
10/16/2008  09:16 PM    <DIR>          jlib
01/06/2008  11:50 PM             6,315 opatch
01/06/2008  11:50 PM             6,961 opatch.bat
01/06/2008  11:50 PM                49 opatch.ini
01/06/2008  11:50 PM             2,571 opatch.pl
10/16/2008  09:16 PM    <DIR>          opatchprereqs
01/06/2008  11:50 PM             2,430 README.txt
               6 File(s)         37,589 bytes
               5 Dir(s)  46,740,713,472 bytes free

D:\oracle\product\10GR2\db_1\OPatch>


0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 23674623
If there is an opatch.bat in the directory it IS what is being called.  Try adding call before it in your batch and the pause afterwards as suggested.

There was a D missed from the oracle_home line too from my copy/pasting, sorry.  Must be tired!

@echo off
set oracle_home=D:\Oracle\product\10GR2\db_1
D:
cd  %ORACLE_HOME%\Opatch

call opatch lsInventory
pause

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 23674630
(The opatch.bat probably calls the perl script in opatch.pl to do some of the work, I imagine, but it is quite a sizable batch file anyway at 6Kb.

Steve
0
 
LVL 6

Expert Comment

by:Brainstormer
ID: 23674902
Try the %comspec% /k option

0
 
LVL 2

Author Comment

by:kaos_theory
ID: 23675086
like this ? it still closed the window


set ORACLE_HOME=D:\Oracle\product\10GR2\db_1

cd %ORACLE_HOME%\Opatch
d:
opatch lsinventory
%comspec% /k
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 23675950
If opatch.bat has EXIT at the end of it then it could be ending and not passing control back to your batch.  The other suggestion above (if simply adding call before your opatch command doesn't work?!) is to run it with, effectively cmd /k as %compsec% will return cmd.exe normally.

i.e.

set oracle_home=....
cd ...
d:
%compsec% /k opatch isinventory

etc.

e.g. if you type cmd /k dir in the Start | run box in winodws it brings up a cmd prompt with a dir command run it and sitting their waiting.
Steve
0
 
LVL 2

Accepted Solution

by:
mikesheard earned 1600 total points
ID: 23683641
Echo it to a file

whatever.bat > whatever.txt
0
 
LVL 6

Expert Comment

by:Justin_W_Chandler
ID: 23750719
Dude -- don't double click the batch file. Open a command prompt and execute it there. It's as simple as that. If you REALLY want to execute it in a new window and keep that window open here's how you can do it:

echo [ENTER A LINE OF CODE HERE] > childbatch.cmd
echo [ENTER ANOTHER LINE OF CODE HERE] >> childbatch.cmd
echo [ENTER EVEN MORE CODE HERE] >> childbatch.cmd
start cmd /k childbatch.cmd

There you have it. you can double click on it all day long and it won't close. Basically it creates another batch file with the commands you want to execute and then starts that batch file by invoking the command prompt with /K switch (/K tells CMD.EXE to remain open after finishing the batch script).
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 23753237
did you ever try adding the word 'call' ?
0
 
LVL 2

Author Comment

by:kaos_theory
ID: 23755363
yeah i  did what is happening i think is that it is callling the pearl script and not returning
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 23755495
You could always have looked into the pearl script batch as suggested for an "exit" command but I guess that is as far as you want to go..
0
 
LVL 2

Author Comment

by:kaos_theory
ID: 23755508
dragon , sorry I meant to split the pionts your comments are valuable

i thank you
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question