【发布时间】:2014-01-17 17:34:49
【问题描述】:
我编写了一个批处理脚本,它位于一个名为 POSTcounter 的 USB 软盘驱动器 (A:) 上,它由 Windows PE 映像中的已修改 (startnet.cmd) 文件自动执行。该脚本只是增加一个值,即帖子的数量,并将该数字写入保存在软盘驱动器上的 txt 文件。此脚本在 Windows 环境命令提示符下运行良好并保存 txt 文件。但是,当脚本在 WinPE 中自动执行时,脚本会运行,但 txt 文件不会更新。
startnet.cmd 包括:
wpeinit
A:\POSTcounter.cmd
POSTcounter.cmd 包括:
@echo off
echo. This script is counting the # of POSTs.
echo.
call:myPOSTTest
for /f "tokens=* delims=" %%x in (TEST.txt) do echo POST# %%x
echo.&pause&goto:eof
::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
--
:myPOSTTest - here starts my function identified by its label
cd "A:\"
if not exist TEST.txt >TEST.txt echo 0
for /f %%x in (TEST.txt) do (
set /a var=%%x+1
)
>TEST.txt echo %var%
goto:eof
【问题讨论】:
-
我们确定它仍然是PE环境中的A:驱动器吗?也许需要更好的 For 循环
for %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if exist %%i:\POSTcounter.cmd set VAR=%%i:
标签: windows batch-file