While writing some Perl test scripts at work, which need drives and partitions to be created and formatted, I hit a road block. When I issued the format command to format a partition, the console running the script kept hanging. After some pondering, I realised that the format command had a safety mechanism, which warned the user that data could be lost and required a user confirmation to proceed with the format. This is a problem while developing automation scripts because the user cannot be expected to be sitting at the console waiting for each and every confirmation prompt by format command. Even so, there was no optional flag which could be specified together with the format command, which would allow it to run without requiring the user to confirm to proceed with the format. This was a problem which I had never faced before. Now, how would I be able to provide the confirmation input without the script hanging?
An idea came to my mind. Now, this idea was neither a stroke of luck, nor was it my experinece in programming. Instead, it was my knowledge in DOS batch file programming. All I had to do was pipe the format command with an echo command. Sounds jibberish? Not at all... Here is how it can be done.
echo y ¦ format
The "y" is a YES to confirm that the format should proceed. This way
Simple eh? Absolutely! But my brain was chewing on this for over 6 hours, before it even dawned to me that it was not for the script to resolve, but instead the console command which the script had to issue.
1 comment:
Thanks a lot , you saved me a life.
I was about to give up.when I stumbled upon your post.
Thanks a lot.
Post a Comment