Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dumb DOS Question 1

Status
Not open for further replies.

pixiepoet

Technical User
Jul 25, 2002
51
0
0
US
I'm a DOS dummy! PLease help me!

I have an XP and am trying to program a DOS batch file to correct some other application. It runs ok, but what line of code should I write to close out the little DOS window that pops up?

I tried "exit" and that doesn't work!
 
In your batch file after 'exit' be sure to hit enter(cursor on next line) before saving.
 
I just tried a small batch file on an XP computer that does a directory and exits, using the "exit" command and it worked. The window closed when it finished.
 
If you are running it from a shortcut, right-click on the shortcut, select Properties, select the Program tab, Check the box for Close on Exit, and select OK.
 
pixiepoet, if you are sure the exit statemaent is there, also make sure the batch gets there, something in the batch may lock it, like stating another bat file?
Insert some Pause statements to test step by step.
Or, if you're in doubt, post the batch file contents here, we can have a look at it.

[sub]If the answer is here, mark it, others can benefit from it too. If 'something' 'somewhere' gives 'some' error, excpect random guesses or no replies at all. Please specify details.
Free Tip: The F1 Key does NOT destroy your PC!
[/sub]
 
YOU ARE ABSOLUTELY RIGHT, MARCS41, the program did HANG and that's why it wouldn't close! However, I have other problems.

BACKGROUND: The .bat program is supposed to fix another program by getting rid of a corrupt file and replacing it with an uncorrupt one. When I got here, the program no longer worked.

The DOS window pops up and says:

"Please wait, fixing DATASHT.DWG . . .
1 file(s) copied.
Could not find G:\DATA\DWGS\PLOT\file*.*"

and this hangs so that the DOS window doesn't close.



The original batch file is as follows:
:*******************************************************
: Batch file used to fix datasht.dwg in TAKEOFF program
:*******************************************************
@echo off
cls
echo Please wait, fixing DATASHT.DWG . . .
map g: = sys:apps\takeoff.r13 > nul
g:
if exist *.tmp del *.tmp
copy g:\apps\takeoff.r13\dwgs\datasht.dwg
cd\data\dwgs\plot
del file*.* > nul
f:
cd\temp
del *.* > nul
cdmap g: = sys: > nul
********************************************************


I didn't understand this code so I altered it and wrote my own, as follows:


:*******************************************************
: Batch file used to fix datasht.dwg in TAKEOFF program
:*******************************************************
@echo off
cls
echo Please wait, fixing DATASHT.DWG . . .
g:
map g: = sys:apps\takeoff.r13 > nul
if exist *.tmp del *.tmp
copy g:\apps\takeoff.r13\dwgs\datasht.dwg
cd\data\dwgs\plot
del *.dwg
f:
cd\temp
del *.dwg
cdmap g: = sys:

*********************************************************

It now closes out ok, but I altered the code so much, not knowing what I am doing. My question is: what is this "> nul" command? I've looked in my books and nothing describes it, so I deleted it, because that is what originally hung. I really want to delete ALL the files (*.*) but when I put that in the code, it hangs again. This time it prompts me by saying "Are you sure you want to delete this? [y/n]" How do I get rid of this? I tried the switch "del *.* /y" but I get an error message. Anyway, if this is too much trouble, I'll just leave it like it is (I'm just not sure it will work like it is supposed to).

Thank you for your help. I'll understand if this is too tedious for you to follow.



 
The 'nul' means : to nothing, into the void.
A del *.* will not work, as you noticed (not even with /y) because the OS prompts you for an input, not a parameter. That can be overcome with something like:
del *.* < y.txt , where y.txt contains the Character Y followed by an Enter (0D +0A), that the same as pressing Y + Enter key.
But since it is mainly DWG's , in your case, keep it simple and use the del *.dwg, you will not get prompted.
Add more lines if more extensions need to be deleted.
So I take it that it works now? [sub]If the answer is here, mark it, others can benefit from it too. If 'something' 'somewhere' gives 'some' error, excpect random guesses or no replies at all. Please specify details.
Free Tip: The F1 Key does NOT destroy your PC!
[/sub]
 
As an add-on...
I cannot tell if it is a long process or not, depends on the number of files, but you could speed up things a little if wanted like this:
You don't have to test for tmp's, just del them, if they don't exist, it displays File not found, and goes on, that's all, but the testing conumes CPU time.

@echo off
cls
echo Please wait, fixing DATASHT.DWG . . .
g:
map g: = sys:apps\takeoff.r13 > nul
del *.tmp
copy g:\apps\takeoff.r13\dwgs\datasht.dwg
del \data\dwgs\plot\*.dwg
del f:\temp\*.dwg
map g: = sys:
[sub]If the answer is here, mark it, others can benefit from it too. If 'something' 'somewhere' gives 'some' error, excpect random guesses or no replies at all. Please specify details.
Free Tip: The F1 Key does NOT destroy your PC!
[/sub]
 
WOW Thanks MARCS41! The code you wrote seems a lot cleaner than mine. Muchas Gracias!
 
You're welcome. [sub]If the answer is here, mark it, others can benefit from it too. If 'something' 'somewhere' gives 'some' error, excpect random guesses or no replies at all. Please specify details.
Free Tip: The F1 Key does NOT destroy your PC!
[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top