在变量中使用> nul [英] Using >nul in a variable
本文介绍了在变量中使用> nul的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人知道如何在变量中设置时忽略> nul
,或者这是不可能的?我有一个感觉,这是只有当所有的变量已经扩展或某事,但它不会伤害要求的工作之一。
示例:
@echo off
::无效
SET pause_5 = ping localhost / n 6> nul
%pause_5%
:: will work
SET pause_5 = ping localhost / n 6
%pause_5%> nul
exit
解决方案
设定「pause_5 = ping localhost / n 6> nul」
pre>
另一个选项是转义将被shell解释的字符:
set pause_5 = ping localhost / n 6 ^> nul
你写的方式本质上说»set
pause_5
到ping localhost / n 6
并忽略set
命令的输出。«Does anyone know how to stop
>nul
being ignored when set in a variable, or is this not possible? I have a feeling that it's one of those things that will only work once all variables have been expanded or something, but it can't hurt to ask.Example:
@echo off :: Won't work SET pause_5=ping localhost /n 6 >nul %pause_5% :: Will work SET pause_5=ping localhost /n 6 %pause_5% >nul exit
解决方案Put quotes around the argument:
set "pause_5=ping localhost /n 6 >nul"
Another option is to escape characters that will be interpreted by the shell:
set pause_5=ping localhost /n 6 ^>nul
But usually the quotes approach is a lot easier.
The way you wrote is essentially said »set
pause_5
toping localhost /n 6
and ignore the output of theset
command.«.这篇关于在变量中使用> nul的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文