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
Batch file 当搜索字符串包含减号字符时,FINDSTR失败_Batch File_Command Line_Windows 8.1 - Fatal编程技术网

Batch file 当搜索字符串包含减号字符时,FINDSTR失败

Batch file 当搜索字符串包含减号字符时,FINDSTR失败,batch-file,command-line,windows-8.1,Batch File,Command Line,Windows 8.1,我将递归地浏览所有JS文件并缩小它们。但是,我必须保留一些完整的JS文件 我将for、dir和findstr组合使用,取得了很大的成功。但是当我想忽略已经缩小的文件(以“-min.js”结尾的文件)时,FINDSTR命令中断了 这是我使用的命令: for /f %i in ('dir /b /a-d /s "D:\update" ^| findstr /liv "\admin" ^| findstr /ile ".js" ^| findstr /vile "-min.js" ^| findstr

我将递归地浏览所有JS文件并缩小它们。但是,我必须保留一些完整的JS文件

我将
for
dir
findstr
组合使用,取得了很大的成功。但是当我想忽略已经缩小的文件(以“-min.js”结尾的文件)时,FINDSTR命令中断了

这是我使用的命令:

for /f %i in ('dir /b /a-d /s "D:\update" ^| findstr /liv "\admin" ^| findstr /ile ".js" ^| findstr /vile "-min.js" ^| findstr /vile ".min.js"') do echo %i
出现以下错误:

FINDSTR: /. ignored
FINDSTR: /j ignored
FINDSTR: Bad command line
FINDSTR: Write error
FINDSTR: Write error
FINDSTR: Write error
FINDSTR: Write error

问题肯定出在
findstr/vile“-min.js”
子句上,但是我不知道为什么连字符会引起问题,因为我使用了/l(literal)标志。

处理
findstr
可执行文件参数的C运行时遵循一组规则。其中一个规则是使用双引号保护单独参数中的空格/特殊字符,但是,一旦命令行标记化并识别参数,在将单独参数传递给主代码之前,将删除引号

这意味着这个命令

findstr/vile“-min.js”
将在可执行文件中作为

argv[0] = findstr 
argv[1] = /vile
argv[2] = -min.js
而且,由于
findstr
接受参数分组(如
/vile
),但它也允许以
//code>或
-
开头的参数,因此
-m
-i
-n
-s
开关(均有效)被接受,但
-.
-j
(未知)被忽略

命令行不正确,因为在参数中找不到搜索字符串

有文档记录的(
findstr/?
)解决方案是使用
/c:“stringToMatch”
语法

findstr/vile/c:“-min.js”
或者您可以使用转义字符,因此
-
不会作为选项参数的初始字符处理

findstr/vile“\-min.js”

试试
“\-min.js”
?@dbenham,也许还需要一个案例。