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