Computing.Net > Forums > Programming > batch file programming

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch file programming

Reply to Message Icon

Name: vande
Date: October 16, 2008 at 04:39:42 Pacific
OS: Windows xp, Windows
CPU/Ram: 2.4 quad core Intel
Product: Dell, Dell, Dell
Comment:

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 "
</b

How 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..........



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: October 16, 2008 at 05:04:42 Pacific
Reply:

If you CALL a second batch the first one is still running.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: Judago
Date: October 16, 2008 at 05:14:19 Pacific
Reply:

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....


0

Response Number 3
Name: vande
Date: October 16, 2008 at 05:45:11 Pacific
Reply:

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 question

I.E.
In CMD i type ipconfig > ipconfig.txt
This works, pretty simple but I will explain more later

So i create a file called random.bat
And within that batch file i put
ipcong > ipconfig.txt
assuming this will do the same

i 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..........


0

Response Number 4
Name: Intel 80486 (by meisinscotland)
Date: October 16, 2008 at 06:47:48 Pacific
Reply:

yuo type exit as the last line

Medion MIM 2080
Toshiba T2130CT
Macintosh Performa 450

All working wonderfully.


0

Response Number 5
Name: klint
Date: October 16, 2008 at 07:00:47 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: vande
Date: October 16, 2008 at 08:52:33 Pacific
Reply:

"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 work

Im guessing this does not work for some reason because of the 1>?


Learning in progress..........


0

Response Number 7
Name: klint
Date: October 16, 2008 at 09:02:28 Pacific
Reply:

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.


0

Response Number 8
Name: vande
Date: October 16, 2008 at 09:44:19 Pacific
Reply:

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 hangs

If 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..........


0

Response Number 9
Name: vande
Date: October 16, 2008 at 09:53:48 Pacific
Reply:

Ok so here is my batch file


ipconfig > C:\ipconfig.txt
call calc.exe

It 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 cause

I 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..........


0

Response Number 10
Name: Judago
Date: October 16, 2008 at 13:57:53 Pacific
Reply:

Try:


start calc

Call 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.


0

Response Number 11
Name: klint
Date: October 16, 2008 at 15:11:27 Pacific
Reply:

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.


0

Response Number 12
Name: vande
Date: October 16, 2008 at 16:10:42 Pacific
Reply:

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..........


0

Response Number 13
Name: klint
Date: October 17, 2008 at 02:30:46 Pacific
Reply:

It depends on how closely related to the current question your new question is.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch file programming

Batch File Programming www.computing.net/answers/programming/batch-file-programming/12397.html

batch file www.computing.net/answers/programming/batch-file/13936.html

Batch File call Registry www.computing.net/answers/programming/batch-file-call-registry/12089.html