如何使用批处理文件将多个命令插入批处理文件 [英] How to insert multiple commands into a batch file using a batch file

查看:107
本文介绍了如何使用批处理文件将多个命令插入批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个批处理文件(我们称它为Create.bat),它将创建一个批处理文件(我们称它为Created.bat),该文件将在其中插入多个命令.

I am making a batch file (Let's call it Create.bat) that will create a batch file (Let's call it Created.bat) that will get multiple commands inserted in it.

其中一个命令如下:

FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %TEST%"') DO IF %%%x == %TEST% goto ProgramON

但是当我运行Create.bat后打开Created.bat进行编辑时,我看到插入了以下代码:

But when I open Created.bat to edit after running Create.bat, I see the following code inserted:

FOR /F %%x == %TEST% goto ProgramON

为什么它会剪掉一部分代码,我该如何解决?

Why does it cut out a portion of the code, and how can I fix it?

推荐答案

某些字符必须转义.其中大多数(&<>|)带有脱字符号(^).百分号与另一个百分号一起转义:

Some characters have to be escaped. Most of them (&<>|) with a caret (^). Percent signs are escaped with another percent sign:

>>created.bat echo DIR ^>nul
>>created.bat echo FOR /F %%%%x IN ('tasklist /NH /FI "IMAGENAME eq %%TEST%%"') DO IF %%%%x == %%TEST%% goto ProgramON

这篇关于如何使用批处理文件将多个命令插入批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆