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 转义特殊字符(%)_Batch File_Escaping_Character - Fatal编程技术网

Batch file 转义特殊字符(%)

Batch file 转义特殊字符(%),batch-file,escaping,character,Batch File,Escaping,Character,我有一个命令,显示其代码附加到的批处理文件的当前名称 echo %~n0%~x0 我希望在不更改其语法的情况下将命令发送到文本文件。 比如, echo %~n0%~x0 >> somefile.txt 我试着用另一个百分比来逃避百分号,但它不起作用 echo %%~n0%%~x0 有什么想法吗?试试插入符号而不是%%like this^%你可能还需要逃避逃避(我知道很奇怪,为什么……但是……你可能会) 使用插入符号对我很有效 echo ^%%~n0^%%~x0 >&g

我有一个命令,显示其代码附加到的批处理文件的当前名称

echo %~n0%~x0 
我希望在不更改其语法的情况下将命令发送到文本文件。 比如,

echo %~n0%~x0 >> somefile.txt
我试着用另一个百分比来逃避百分号,但它不起作用

echo %%~n0%%~x0 

有什么想法吗?

试试插入符号而不是%%like this^%你可能还需要逃避逃避(我知道很奇怪,为什么……但是……你可能会)

使用插入符号对我很有效

echo ^%%~n0^%%~x0 >> somefile.txt
此代码将生成批处理文件名
echo^%~n0^%~x0>>somefile.txt

插入符号只能直接在命令提示符下工作;在批处理文件中,您通常需要将
%
符号加倍…@aschipfl这是批处理文件中的我的代码,它适用于我echo^%%~n0^%%~x0>>somefile.txt您可以使用插入符号,但是它在没有插入符号的情况下也会以同样的方式工作。@zask-如果答案对您有帮助-请标记为答案。
echo%%~n0%%~x0
在批处理文件中按预期工作(输出
%~n0%~x0
),您应该在失败的地方显示最小批处理文件。或者至少你得到了什么结果