PC Review


Reply
Thread Tools Rate Thread

Defrag/shutdown batch file

 
 
Oni
Guest
Posts: n/a
 
      17th Jun 2009
I've scheduled a batch file to run defrag and then shutdown the system but
the shutdown command seems to be executed immedialty after the defrag
command. This results in defrag never finishing. can anyone shed some light
on this.

Batch file contains the following:

start /WAIT defrag c: -f
shutdown -s

Thanks in advance
--
Regards
Oni
 
Reply With Quote
 
 
 
 
Thee Chicago Wolf (MVP)
Guest
Posts: n/a
 
      17th Jun 2009
>I've scheduled a batch file to run defrag and then shutdown the system but
>the shutdown command seems to be executed immedialty after the defrag
>command. This results in defrag never finishing. can anyone shed some light
>on this.
>
>Batch file contains the following:
>
>start /WAIT defrag c: -f
>shutdown -s
>
>Thanks in advance


That's the nature of a batch file. Why not just created some scheduled
tasks that do this instead?

- Thee Chicago Wolf (MVP)
 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a
 
      17th Jun 2009

"Oni" <(E-Mail Removed)> wrote in message
news:4A1C70B5-EF9A-4A87-B66C-(E-Mail Removed)...
> I've scheduled a batch file to run defrag and then shutdown the system but
> the shutdown command seems to be executed immedialty after the defrag
> command. This results in defrag never finishing. can anyone shed some
> light
> on this.
>
> Batch file contains the following:
>
> start /WAIT defrag c: -f
> shutdown -s
>
> Thanks in advance
> --
> Regards
> Oni


The behaviour you observe is probably self-inflicted. Try this instead:
@echo off
defrag c: -f
shutdown -s

Or this:
@echo off
defrag c: -f
:Loop
ping localhost -n 60 > nul
tasklist | find /i "defrag" > nul && goto Loop
shutdown -s


 
Reply With Quote
 
Oni
Guest
Posts: n/a
 
      17th Jun 2009

"Pegasus [MVP]" wrote:

>
> "Oni" <(E-Mail Removed)> wrote in message
> news:4A1C70B5-EF9A-4A87-B66C-(E-Mail Removed)...
> > I've scheduled a batch file to run defrag and then shutdown the system but
> > the shutdown command seems to be executed immedialty after the defrag
> > command. This results in defrag never finishing. can anyone shed some
> > light
> > on this.
> >
> > Batch file contains the following:
> >
> > start /WAIT defrag c: -f
> > shutdown -s
> >
> > Thanks in advance
> > --
> > Regards
> > Oni

>
> The behaviour you observe is probably self-inflicted. Try this instead:
> @echo off
> defrag c: -f
> shutdown -s
>
> Or this:
> @echo off
> defrag c: -f
> :Loop
> ping localhost -n 60 > nul
> tasklist | find /i "defrag" > nul && goto Loop
> shutdown -s
>
>
>

Thanks for helping out, both solutions worked like a charm.

Would you care to elaborate why my original batch wouldn't work?
QUOTE<The behaviour you observe is probably self-inflicted.>

--
Regards
Oni


 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a
 
      17th Jun 2009

"Oni" <(E-Mail Removed)> wrote in message
news:51D50A67-4343-416A-9AA8-(E-Mail Removed)...
>
> "Pegasus [MVP]" wrote:
>
>>
>> "Oni" <(E-Mail Removed)> wrote in message
>> news:4A1C70B5-EF9A-4A87-B66C-(E-Mail Removed)...
>> > I've scheduled a batch file to run defrag and then shutdown the system
>> > but
>> > the shutdown command seems to be executed immedialty after the defrag
>> > command. This results in defrag never finishing. can anyone shed some
>> > light
>> > on this.
>> >
>> > Batch file contains the following:
>> >
>> > start /WAIT defrag c: -f
>> > shutdown -s
>> >
>> > Thanks in advance
>> > --
>> > Regards
>> > Oni

>>
>> The behaviour you observe is probably self-inflicted. Try this instead:
>> @echo off
>> defrag c: -f
>> shutdown -s
>>
>> Or this:
>> @echo off
>> defrag c: -f
>> :Loop
>> ping localhost -n 60 > nul
>> tasklist | find /i "defrag" > nul && goto Loop
>> shutdown -s
>>
>>
>>

> Thanks for helping out, both solutions worked like a charm.
>
> Would you care to elaborate why my original batch wouldn't work?
> QUOTE<The behaviour you observe is probably self-inflicted.>
>
> --
> Regards
> Oni


Some executable files, when invoked in a batch file, will return control to
the batch file immediately. Write.exe is one of them. Others will cause the
batchfile to pause until they have done their job. Notepad.exe belongs to
this class.

You can cause a batch to resume its work immediately if you launch the
second type of program in its own shell. Here is how it's done:
start /b "My Notepad" notepad.exe

Your defrag program belongs to the second class. It would have paused the
batch file until it had done its job. Since you used the "start" command,
you forced it to hand control back to the batch file immediately - which was
the opposite of what you wanted to achieve.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
batch file at shutdown ToddAndMargo Windows XP General 3 25th Mar 2009 09:15 PM
Scheduling Defrag in a batch file =?Utf-8?B?QnJhZA==?= Windows XP Performance 1 18th Oct 2004 02:27 PM
Run batch file at shutdown? Vance Green Microsoft Windows 2000 2 28th Feb 2004 12:28 AM
Defrag Batch File Devon Windows XP Performance 2 21st Nov 2003 03:40 PM
running a defrag via a batch file? Aaron Microsoft Windows 2000 CMD Promt 1 8th Aug 2003 09:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:03 PM.