Batch script - Closing separate cmd windows opened by batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
excessium
Posts: 2
Joined: 31 Mar 2015 02:11

Batch script - Closing separate cmd windows opened by batch

#1 Post by excessium » 31 Mar 2015 02:36

Hello world,

I'm new to this forum and decided to join to get som knownledge and hopefully help on my way.

The past few days I have been working on a script that I thought would be rather easy but it seems not, and I do understand why. My problem is how to get around it.

The batch script I need explained:
At work I have a script that runs in cmd.exe that does a bunch of things like moving a huge amount of files from a location to another. Lets call it movefile.cmd This script works, but happens to stop (not crash) sometimes. Its important that this script always runs, so my idea here was to create a batch that exits cmd.exe and then re-opens the script each hour or so. Lets call this script restartcmd.bat

Sounds perfectly easy as I could do this:
@echo off
:loop
start c:\script\movefile.cmd
Timeout /nobreak /t 3600
Taskkill cmd.exe
goto loop

But obviously this doesnt work because my new script also runs in cmd.exe, so it would kill this process as well.

What I've tried:
So I made a copy of cmd.exe and renamed it into dontkillthis.exe. I run dontkillthis.exe and then open the restardcmd.bat from dontkillthis.exe - this works perfectly! But I need to be able to just dobbleclick my script instead of doing that. Why? Because its supposed to be as easy as possible and I want my restartcmd.bat to be in my startup folder.

I've been looking at the ideas of getting the exact process ID of cmd.exe and shutting that so that my dontkillthis.exe will remain, but I can't seem to nail it.

I'm not sure if I'm being confused or if it actually is a bit hard to do this.

I'd really appreciate some help here.

Best Regards
New member Excessium

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch script - Closing separate cmd windows opened by ba

#2 Post by foxidrive » 31 Mar 2015 02:39

excessium wrote:I have a script that runs in cmd.exe that does a bunch of things like moving a huge amount of files from a location to another. Lets call it movefile.cmd This script works, but happens to stop (not crash) sometimes. Its important that this script always runs


How about solving the reason why it stops?

Seeing the batch file would help.

excessium
Posts: 2
Joined: 31 Mar 2015 02:11

Re: Batch script - Closing separate cmd windows opened by ba

#3 Post by excessium » 31 Mar 2015 03:10

foxidrive wrote:
excessium wrote:I have a script that runs in cmd.exe that does a bunch of things like moving a huge amount of files from a location to another. Lets call it movefile.cmd This script works, but happens to stop (not crash) sometimes. Its important that this script always runs


How about solving the reason why it stops?

Seeing the batch file would help.


Thanks for your reply, but that is not an option in this case bacause that script works with a lot of different filetypes that it recieves from external customers. With other words, it most likely stops when they send some files that are corrupt, wrong filetype, too big or something similar. Also, its not my script and the script runs "through" another software of some sort that I'm not familiar with. Its probably just 1/1000 files that it can't handle, so I'm not going to look into that. :shock:

Post Reply