[英]Windows Batch file - pipe to FIND
Trying to test a string to see if it contains a substring in a Windows batch file. 尝试测试字符串以查看它是否包含Windows批处理文件中的子字符串。
This is what I have so far: 这是我到目前为止:
echo %1 | find "message"
if %errorlevel% == 0 echo contains string
The command line output for this is (the contents of %1 was "messages\\Message.js"): 这个命令行输出是(%1的内容是“messages \\ Message.js”):
messages\Message.js contains string
The issue I am having is that the only way I can get this to work is with the exact line: echo %1 | find "js"
我遇到的问题是,我能使用它的唯一方法是使用确切的行:
echo %1 | find "js"
echo %1 | find "js"
. echo %1 | find "js"
。
How can I do this without echoing the file path each time? 如何在不回显文件路径的情况下执行此操作? When I remove the
echo
, the operating system attempts to open the file. 当我删除
echo
,操作系统会尝试打开该文件。 I would love to save the file path to a variable, but nothing I tried worked, I always ended up with an empty variable. 我希望将文件路径保存到变量,但我尝试过没有任何工作,我总是得到一个空变量。
echo %1 | find "message" > NUL
if %errorlevel% == 0 echo contains string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.