Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows批处理脚本在两个不同的服务器上运行时产生意外结果_Windows_Batch File - Fatal编程技术网

Windows批处理脚本在两个不同的服务器上运行时产生意外结果

Windows批处理脚本在两个不同的服务器上运行时产生意外结果,windows,batch-file,Windows,Batch File,我有下面的批处理脚本,它给了我意想不到的结果。当我在服务器A上运行时,它总是写入“Yes\u unterming.txt”文件,即使我的文件abc.txt有0 但当我在不同的windows服务器B上运行时,它给出了正确的结果。不确定服务器a出了什么问题 @echo off for %%i in (%~dp0abc.txt) do ( findstr /x /c:"0" "%%i" if errorlevel 1 (type NUL > %~dp0Yes_Outstanding.txt)

我有下面的批处理脚本,它给了我意想不到的结果。当我在服务器A上运行时,它总是写入“Yes\u unterming.txt”文件,即使我的文件abc.txt有0

但当我在不同的windows服务器B上运行时,它给出了正确的结果。不确定服务器a出了什么问题

@echo off

for %%i in (%~dp0abc.txt) do (
findstr /x /c:"0" "%%i"
if errorlevel 1 (type NUL > %~dp0Yes_Outstanding.txt) else (type NUL > %~dp0No_Outstanding.txt)
)

请提供帮助。

为什么要使用FOR命令?此代码中不需要它。服务器A上的文件夹是否有空间?习惯于总是用引号括起路径和文件名。服务器A上的文件是否只包含
0
而不是
0
?Windows版本如何,两台服务器上的版本相同?Windows脚本有时在不同操作系统版本中的行为有所不同……正如前面提到的,不需要for循环
FINDSTR/LX“0”“%~dp0abc.txt”>NUL&&&(匹配成功时的命令)| |(匹配失败时的命令)
此外,您正在读取和写入脚本的位置;您需要确保您在该位置具有写入权限。我已删除for循环,并且以下脚本仍没有在服务器A@echo off findstr/x/c上运行:“0”“%~dp0abc.txt”如果错误级别为1(键入NUL>%~dp0Yes_untible.txt)或者(键入NUL>%~dp0No_untible.txt)。。。我检查了A&B服务器上的Windows版本,它们都是相同的。在服务器B上,上述脚本的权限没有问题。为什么要使用FOR命令?此代码中不需要它。服务器A上的文件夹是否有空间?习惯于总是用引号括起路径和文件名。服务器A上的文件是否只包含
0
而不是
0
?Windows版本如何,两台服务器上的版本相同?Windows脚本有时在不同操作系统版本中的行为有所不同……正如前面提到的,不需要for循环
FINDSTR/LX“0”“%~dp0abc.txt”>NUL&&&(匹配成功时的命令)| |(匹配失败时的命令)
此外,您正在读取和写入脚本的位置;您需要确保您在该位置具有写入权限。我已删除for循环,并且以下脚本仍没有在服务器A@echo off findstr/x/c上运行:“0”“%~dp0abc.txt”如果错误级别为1(键入NUL>%~dp0Yes_untible.txt)或者(键入NUL>%~dp0No_untible.txt)。。。我检查了A&B服务器上的Windows版本,它们都是相同的。上述脚本在服务器B上运行正常,没有权限问题。