读取文本文件并进行反应(批处理)

时间:2017-05-10 02:25:52

标签: batch-file cmd

我找了很长时间,找不到解决问题的好办法。我想要一个批处理程序在.txt文件中“查找”命令“”,如果该单词在其中,则执行不同的命令。如果命令存在,我会想做set %textfile%=text.txt这样的事情,如果有效,我会做if %textfile%==update goto update这将是一个简单的方法来启动自动更新,如果这是一个循环。基本上,是否有一个命令在%text%中设置文本文件?这是我试图将其添加到的代码:

@echo off
color 0f
:start
echo Welcome to Master control pannel
ping 127.1 -n 4 >nul
cls
:options
cls
echo What would you like to do first? (Type the number of the operation you want to start)
echo.
ping 127.1 -n 2 >nul
echo 1. Run a command off of all computers 
::(I want to run a command by sending a message to a text file but want recieving computor to be able to read it and execute it, how could I read the command and then do what it say, for example, if the command says "echo Hello" I would want recieving computor to say "Hello" )
echo 2. Stops the current command
echo 3. List all computers
echo 4. Open remote shutdown program
echo 5. Delete a computor (in progress) 
echo 6. (Unfinished)
echo 7. (Unfinished)
echo 8. (Unfinished)
echo 9. (Unfinished)
echo 10. Exit
set /p choose=(1-9):
if %choose%==1 goto o1
if %choose%==2 goto o2
if %choose%==3 goto o3
if %choose%==4 goto o4
if %choose%==5 goto o5
if %choose%==6 goto close
if %choose%==7 goto close
if %choose%==8 goto close
if %choose%==9 goto close
if %choose%==10 goto o10
goto options
:close
cls
goto start
:o1
echo Stopping current command
del command.txt
echo. 2>command.txt
echo Command stopped!
pause
cls
goto start

我非常感谢对我能做的或对此添加的一些帮助或评论。谢谢!

1 个答案:

答案 0 :(得分:0)

不是答案,而是几个提示。

  • 变量只能包含单行而不包含整个文件。
  • 如果你想把文件的第一行变成var,请使用`Set / P" var ="
  • set %textfile%=text.txt会将test.txt字面存储到var中,其名称是var textfile的内容。
  • 您正在使用标签
  • 混合goto o1:01

`