findstr和&&不能一起玩

时间:2018-09-09 13:59:10

标签: batch-file

这应该用来检测哪个错误是从7z.exe发送到"%temp%\error.unp"并采取相应措施的。但是,&&之后的findstr根本不起作用,永远不会执行特定命令。我在做什么错了?

type "%temp%\error.unp" || findstr /c:"Wrong password" && set /p "password=enter password other than fanedit.org: " && goto security
type "%temp%\error.unp" || findstr /c:"not enough space" && rmdir /s /q %drive%\$recycle.bin && echo disk was full, recycle bin emptied out.

1 个答案:

答案 0 :(得分:2)

如对Proteks答案的评论中所述,您将需要用括号括起来。
然后,无需在一行中塞满所有内容。 仅对错误级别做出反应意味着您应使用>Nul 2>&1

禁止其他输出

编辑:由于@sst的提示,重定向顺序颠倒了
试试:

type "%temp%\error.unp" | findstr /c:"Wrong password" >Nul 2>&1 &&(
    set /p "password=enter password other than fanedit.org: " 
    goto security
)
type "%temp%\error.unp" | findstr /c:"not enough space" >Nul 2>&1 &&( 
    rmdir /s /q %drive%\$recycle.bin
    echo disk was full, recycle bin emptied out.
)