I want to make a automated program in .bat. The program needs to run a command. However, the command must be run from a custom CMD.
我想在.bat中制作一个自动程序。该程序需要运行命令。但是,必须从自定义CMD运行该命令。
If I open a regular CMD, the commands that I will do:
如果我打开常规CMD,我将执行的命令:
- C:\Hardware\bin\StartCustomCMD.bat init (This is the first thing I will type. It starts the custom CMD.)
- bb autobuild (This is the second thing that I will type. The command goes into the custom CMD)
C:\ Hardware \ bin \ StartCustomCMD.bat init(这是我要输入的第一件事。它启动自定义CMD。)
bb autobuild(这是我要输入的第二件事。该命令进入自定义CMD)
You can probably tell that I did not write these scripts. I am trying to set this up in Windows Scheduler so that the script gets run automatically every day. Any help on how can I do that?
您可以说我没有编写这些脚本。我试图在Windows Scheduler中设置它,以便脚本每天自动运行。有什么帮助,我该怎么办?
Thanks.
2 个解决方案
#1
0
Make yourself a new batch file, and embed the other things into it, and then run that.
让自己成为一个新的批处理文件,并将其他内容嵌入其中,然后运行它。
@echo off
call C:\Hardware\bin\StartCustomCMD.bat
bb autobuild
If bb
it itself a batch file, then use call
on it also. What call
does is execute another batch file, and then continue processing. If you don't use call
, when you run one batch file from another, the latter 'takes over' and the caller does not continue.
如果bb本身就是一个批处理文件,那么也可以使用它。调用的是执行另一个批处理文件,然后继续处理。如果您不使用呼叫,当您从另一个批处理文件运行时,后者“接管”并且呼叫者不会继续。
#2
0
To do this you can use the timeout and goto command. Timeout waits a period of time in seconds but it can be skipped by pressing any key while cmd is open at the top layer. If you can see cmd press its icon on the desktop until you can not see it. Then using the goto command you can go to the top line. So here would be your script:
为此,您可以使用timeout和goto命令。超时会以秒为单位等待一段时间,但在顶层打开cmd时按任意键可以跳过超时。如果您可以看到cmd按下桌面上的图标,直到您看不到它为止。然后使用goto命令,您可以转到顶行。所以这将是你的脚本:
:start
C:\Hardware\bin\StartCustomCMD.bat init
bb autobuild
timeout 86400
goto start
You already know what the first two commands do, but timeout 86400
waits exactly one day then the goto start
command goes to the first command so that gets repeated. If you need to add any more commands then put them above the timeout 86400
command.
您已经知道前两个命令的作用,但是超时86400正好等待一天,然后goto start命令转到第一个命令,以便重复。如果您需要添加更多命令,请将它们置于超时86400命令之上。
#1
0
Make yourself a new batch file, and embed the other things into it, and then run that.
让自己成为一个新的批处理文件,并将其他内容嵌入其中,然后运行它。
@echo off
call C:\Hardware\bin\StartCustomCMD.bat
bb autobuild
If bb
it itself a batch file, then use call
on it also. What call
does is execute another batch file, and then continue processing. If you don't use call
, when you run one batch file from another, the latter 'takes over' and the caller does not continue.
如果bb本身就是一个批处理文件,那么也可以使用它。调用的是执行另一个批处理文件,然后继续处理。如果您不使用呼叫,当您从另一个批处理文件运行时,后者“接管”并且呼叫者不会继续。
#2
0
To do this you can use the timeout and goto command. Timeout waits a period of time in seconds but it can be skipped by pressing any key while cmd is open at the top layer. If you can see cmd press its icon on the desktop until you can not see it. Then using the goto command you can go to the top line. So here would be your script:
为此,您可以使用timeout和goto命令。超时会以秒为单位等待一段时间,但在顶层打开cmd时按任意键可以跳过超时。如果您可以看到cmd按下桌面上的图标,直到您看不到它为止。然后使用goto命令,您可以转到顶行。所以这将是你的脚本:
:start
C:\Hardware\bin\StartCustomCMD.bat init
bb autobuild
timeout 86400
goto start
You already know what the first two commands do, but timeout 86400
waits exactly one day then the goto start
command goes to the first command so that gets repeated. If you need to add any more commands then put them above the timeout 86400
command.
您已经知道前两个命令的作用,但是超时86400正好等待一天,然后goto start命令转到第一个命令,以便重复。如果您需要添加更多命令,请将它们置于超时86400命令之上。