windows 如何从文本文件执行cmd命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19075543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:56:38  来源:igfitidea点击:

How to execute cmd command from text file?

windowsbatch-filecmd

提问by Matt Martin

As title says, I need to execute cmd command from text file.Let's say I have text file called fileand in it it's written Color A.I need something like command: type file.txtand not just write it on screen, but I want it to press enter meanwhile.Batch file options are welcomed too.Thank you.

正如标题所说,我需要从文本文件中执行 cmd 命令。假设我调用了文本文件file并在其中写入了它Color A。我需要类似 command: 的东西type file.txt,而不仅仅是将它写在屏幕上,但我希望它同时按下 Enter 键。也欢迎批处理文件选项。谢谢。

回答by Vikalp Patel

You can use save your normal file with batch programming in it with .batextension. And run that file WhateverNameItIs.baton your command prompt.

您可以使用.bat扩展名保存带有批处理编程的普通文件。并WhateverNameItIs.bat在命令提示符下运行该文件。

Saved it as file.bat

将其另存为 file.bat

 @ECHO ON
 ECHO Color A

In your case you can drag file from your where your are to command prompt. Or Using CDyou can reach out where your file is saved within your command prompt. Fire up file.baton your command prompt will execute whatever batch programming is written on that file.

在您的情况下,您可以将文件从您所在的位置拖到命令提示符处。或者使用CD您可以在命令提示符中访问文件的保存位置。火起来file.bat的命令提示符将执行任何批处理编程是在该文件上写的。

回答by boba fett

you can use

您可以使用

xcopy Name.txt (your Folder)
ren Name.txt Name.bat
call Name.bat (or full location of Name.bat)

it should work

它应该工作