Originally posted by lxmxn at 2006-10-28 13:09:
不难看出,以上willsort兄写的批处理要在系统盘根目录中运行,而这段代码中并没有删除"boot.ini"文件的语句,但是后面的这句让我感到质疑:"copy %temp%\boot.new boot.ini>nul 2>nul",这里会把"%temp%\boot.new" copy 到当前的工作目录中来,也就是 copy 到系统盘的根目录中来,并且将文件名改为"boot.ini",而此时系统盘的根目录里面已经有了一个"boot.ini"文件,这时 copy 命令就要询问你是否改写原来的"boot.ini"文件,而willsort兄只是简单的在后面加上">nul 2>nul"这个屏蔽的语句,这样一来,系统就好象死锁在一种询问的状态,当然CMD窗口并没有任何的提示。这显然没有达到我们的目的,结果显然是 copy 失败了。
这就是经验多少的问题了
你如何实际测试过这段代码的话
就会明白其中的奥妙
copy 有一个控制是否覆盖同名文件的开关 /y
在命令行下这个开关缺省关闭
在批处理中这个开关缺省开启
所以在批处理中copy是不需要/y开关的
除非有环境变量copycmd,并且指定了/-y的值
Originally posted by lxmxn at 2006-10-28 13:09:
It is not difficult to see that the above batch processing written by brother willsort needs to be run in the root directory of the system disk, and there is no statement to delete the "boot.ini" file in this code. But the following sentence makes me question: "copy %temp%\boot.new boot.ini>nul 2>nul". Here, it will copy "%temp%\boot.new" to the current working directory, that is, to the root directory of the system disk, and change the file name to "boot.ini". At this time, there is already a "boot.ini" file in the root directory of the system disk. At this time, the copy command will ask you whether to rewrite the original "boot.ini" file. However, brother willsort simply adds the " >nul 2>nul" shielding statement at the back. In this way, the system seems to be deadlocked in a questioning state. Of course, the CMD window has no prompts. This obviously does not achieve our purpose, and the result is obviously a copy failure.
This is a matter of experience.
If you have actually tested this code,
you will understand the mystery.
There is a switch /y for copy to control whether to overwrite the file with the same name.
In the command line, this switch is off by default.
In batch processing, this switch is on by default.
So in batch processing, copy does not need the /y switch.
Unless there is an environment variable copycmd and /-y value is specified.