Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
This was takin from another post
>"About your question on deleting the batch file the answer is NO, a batch file can't delete itself "
</bHow about this could you have your first batch file end but before it does it calls a second batch file and then in this second batch file it will delete the first batch file? Microsoft or someone needs a self destruct method :)
Learning in progress..........

If you CALL a second batch the first one is still running.
=====================================
If at first you don't succeed, you're about average.M2

Both
del %0
and
START CMD /C DEL %0
Seem to work fine to me, the later even got in a command after getting another instance of cmd to delete it.[edit]
I just got one batch to call another batch that deleted it, all it seemed to do was end the script after the call. Kind of brings new meaning to "end of file" ending a script....

I just got one batch to call another batch that deleted it, all it seemed to do was end the script after the call. Kind of brings new meaning to "end of file" ending a script....
So I would guess this answer's part of my questionI.E.
In CMD i type ipconfig > ipconfig.txt
This works, pretty simple but I will explain more laterSo i create a file called random.bat
And within that batch file i put
ipcong > ipconfig.txt
assuming this will do the samei double click the batch file random.bat
But it hangs on the CMD window and until i click the X to close it it will not complete !!!!
I want this to run behind the scene without any user interaction
Why wont the window close?
how do i make it close and "complete" automatically?Learning in progress..........

yuo type exit as the last line
Medion MIM 2080
Toshiba T2130CT
Macintosh Performa 450All working wonderfully.

It's probably caused by your default console window being set to not close when the program terminates. Don't worry, the batch file does in fact complete. It's just that the window doesn't disappear. Its title does say "Inactive command prompt", right?
If you want it to disappear, you can go to the window's menu and select Properties.

"you type exit as the last line"
Tried this but the problem is that let me show you
I type manually in CMD
ipconfig > ipconfig.txt and ipconfig.txt is created with the results of typing ipconfig in your Command. So really that works correctly.Then i say ok open notepad type ipconfig > ipconfig.txt and it should do the same thing i save the file as random.bat (anything.bat) and double click it and the cmd window hangs open with the exact thing typed below
ipconfig 1>C:\ipconfig.txt
What is going on ? why is there a 1 here 1>
if i click X and close the window it works
Don't worry, the batch file does in fact complete. It's just that the window doesn't disappear
The way I 100% know that it in fact does not work when created in a .bat file is that when I do it maually in CMD it creates ipconfig.txt As its suppose to
Now it will in the .bat version of running the same command but only if i click the x and exit the CMD window and having the exit at the end of the code does not workIm guessing this does not work for some reason because of the 1>?
Learning in progress..........

No, it's nothing to do with the 1>, that's quite normal. It's because > is shorthand for 1> so when the batch file echos the command, it echos it in full. 1> means "redirect standard output" and you can also do 2> which means "redirect standard error."
Back to your problem - I don't know the answer, yet. Can you try adding another command on a new line after the ipconfig command, and tell me if the batch file now hangs on the second command.

Well i assume cause it dont go to the next line with exit that it is hanging on ipconfig > ipconfig.txt
So again I hit start then run then type CMD inside cmd i type ipconfig >ipconfig.txt and everything works
If i open notpad type ipconfig >ipconfig.txt
then save the note pad as random.bat
then run the .bat it hangsIf you can, can you try it out ?
It still works but it needs the cmd window to close first and if i typr cls at the end of ipconfig >ipconfig.txt then it works and closes window but it cls the ipconfig.txt which in the end is usless :)
But i will try as suggested i can call calc.exe or something to that nature i will get back to you but read the above in the mean time and maybe you can re analyze this whole thing
Learning in progress..........

Ok so here is my batch file
ipconfig > C:\ipconfig.txt
call calc.exeIt does open calc.exe however there is no ipconfig.txt
Ok for some reason it works lol not sure what i did wrong but .........
Anywho back to the batching i still would like to know if there is a command when doing batch files that closes windows causeI have a defrag script that runs and it prompts the user by calling a notepad that says what it is doing however it wont continue until you close the notepad window how can i get by this?
Learning in progress..........

Try:
start calcCall waits for the operation to be completed, if you call in a gui app like calc the batch will wait until you close the application.

I forgot to mention it but I did try your batch file when you first wrote about it. It worked perfectly. I still don't know why yours doesn't. I have heard of people having problems with the ipconfig command hanging when they have a dodgy network connection. But I've never heard of ipconfig hanging when you run it from a batch file but not when you run it from the command file.
Anyway, as others have said, if you run Notepad from your batch file, it will wait for Notepad to exit before continuing with the batch file. To prevent waiting, use this command:
start Notepad.exe filename.txt
Alternatively, instead of running Notepad, you may prefer to display the text in the cmd window with this command:
type filename.txt
Follow this with your defrag command.

Ok thank you for the response and i did get ipconfig to work im not really sure how but i got it to work maybe i was doing something wrong from the start.
Should I start my next question? Or should I start a new thread?
Learning in progress..........

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |