我在下面有一个小脚本,我将其上传到 GitHub 以自动化一些流程:
script.bat(已上传至GitHub)
@echo off
set "folder=%random%%random%%random%"
mkdir "%temp%\%folder%"
cd "%temp%\%folder%"
curl --silent <link> >mainfile.bat
curl --silent <link> >mainfile2.bat
curl --silent <link> >mainfile3.bat
curl --silent <link> >mainfile4.bat
curl --silent <link> >mainfile5.bat
::some tasks involving downloaded batch files here...
del mainfile3.bat
del mainfile4.bat
del mainfile5.bat
start /wait mainfile.bat 2>nul
rmdir "%temp%\%folder%"
我通过在计算机上运行
curl --silent https://raw.githubusercontent.com/***/***/main/script.bat|cmd /q /k
来运行此文件。
问题是,我在控制台末尾看到了
More?
,但我不知道为什么。尝试使用 |cmd /k
再次运行脚本,发现它发生在 start /wait mainfile.bat 2>nul
之后。
这以前不是问题,我无法找出导致问题的原因。
这是根据您发布的内容编写的批处理脚本示例,其中包含正确的
Call
命令(而不是 Start
)以及其他改进。
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion
:TmpDir
Set "folder=%Temp%\%RANDOM%%RANDOM%%RANDOM%"
If Exist "%folder%\." (GoTo TmpDir) Else MD "%folder%" 2>NUL
PushD "%folder%" 2>NUL || Exit /B
%SystemRoot%\System32\curl.exe --silent "https://raw.githubusercontent.com/***" 1>"mainfile.cmd"
%SystemRoot%\System32\curl.exe --silent "https://raw.githubusercontent.com/***" 1>"mainfile2.cmd"
%SystemRoot%\System32\curl.exe --silent "https://raw.githubusercontent.com/***" 1>"mainfile3.cmd"
%SystemRoot%\System32\curl.exe --silent "https://raw.githubusercontent.com/***" 1>"mainfile4.cmd"
%SystemRoot%\System32\curl.exe --silent "https://raw.githubusercontent.com/***" 1>"mainfile5.cmd"
Rem some tasks involving downloaded batch files here...
Del /Q "mainfile3.cmd" "mainfile4.cmd" "mainfile5.cmd"
Call "mainfile.cmd" 2>NUL
PopD
RD "%folder%"
我应该补充一点,如果您在
mainfile2.cmd
ete 之前运行脚本 mainfile3.cmd
、mainfile4.cmd
、mainfile5.cmd
或 Del
,请在它们前面加上 Call
,就像所示的 mainfile.cmd
一样。
我还应该提到,如果脚本
mainfile3.cmd
、mainfile4.cmd
或 mainfile5.cmd
不应该被 mainfile.cmd
中的全局/通配符忽略,您可以删除 Del
行, (无论如何,这些都将由 RD
命令处理)。