Saturday, June 23, 2007

"Sleep"ing in Win XP (batch files)

All examples using choice(.com) which would be among the first hits on a search don't work because Windows XP doesn't come with choice.com by default. Solutions are to get it from Win9x, a (WinNT/2003Server) resource kit, or off the MS site; or to use QBasic or a ping trick such as: ping 127.0.0.1 -n %1% -w 1000> nul

But the best solution I could find that works straight out of the box is:

@echo off
echo Starting!
echo Wscript.Sleep 10000> sleep.vbs
start /w wscript.exe sleep.vbs
echo Done!
del sleep.vbs
Off:
http://www.ericphelps.com/batch/samples/sleep.txt

As mentioned there:
1) Millisecond accuracy.
2) No 100% utilization of CPU i.e. no for(i = 1 to 1 billion) loops.

Wednesday, June 13, 2007

Foolishness and recovery

(Warning: Some background knowledge about the working of CVS is needed to understand this paragraph.) One of the few ways to kick yourself in the foot with CVS is to create a new file (in this case, a .java); forget to add it to the CVS; commit the other files; and then try to test if the build works by deleting the whole folder and checking out again there.

Short story short, three hours of hard (copy-paste) work was going to go down the drain. The file had gone; I had to recover it.

Google. The first result was this supposedly oft-used program called DiskInternals Uneraser available from http://www.diskinternals.com/. The program took quite some time to scan the partition and then did find the deleted .java and .class file, but said it needed the paid version (~10$) to actually recover them. Searching for a crack (using a GNU/Linux box, of course) was in vain. Some site actually made me download a .zip and then had a file in it which read:
S/N: Evalution

I searched some more and found:
http://www.ntfsundelete.com/
A nice piece of gratis software from a company known as Atola Technologies, this product did the job well. It scanned through the disk faster, had a better interface than the DiskInternals Uneraser, and managed to try to recover the files without any payment of any sort. It turned out that the .java file couldn't be recovered fully, but the .class file could. But I did need the source. Then comes another gratis software cavaj (downloadable from http://www.bysoft.se/sureshot/cavaj/) to the rescue. Cavaj gracefully created the .java from the class file, and this .java was almost compilable. Just a one line change, and I had my file back!