gpt4 book ai didi

windows - 从命令行执行远程 bat 文件时传递 Y/N

转载 作者:可可西里 更新时间:2023-11-01 09:36:47 26 4
gpt4 key购买 nike

我正在尝试执行远程批处理文件。我可以使用 PsExec 调用批处理文件,但由于批处理文件中的 :choice 而无法完成。

这是批处理文件的片段

:choice
set /P c=Are you sure you want to continue [Y/N]?
if /I "%c%" EQU "Y" goto :execute_script
if /I "%c%" EQU "N" goto :END
goto :choice

填充问题

enter image description here

我想通过如下命令处理这个问题:

cmd /c start C:\temp\PSEXEC\PsExec.exe \\server -u username -p password cmd /c (^cd C:\BatchExecutors ^& SnapExecutor.bat location^)

建议表示赞赏。提前致谢。

最佳答案

当 2 个批处理文件具有相同的标签时,您可以使用一个奇怪的 CMD 行为来绕过这个问题。但是问题之前的任何代码都将被忽略。

为此,创建另一个包含此内容的批处理文件:

    call :execute_script
goto:eof
:execute_script
cd /D C:\BatchExecutors
SnapExecutor.bat %*

所以这里发生的是这个脚本将调用 SnapExecutor.bat,但不是从脚本的开头开始,而是从 :execute_script 开始

现在的问题是如何远程执行。您可以使用以下命令在远程可写文件夹中创建此脚本:

    cmd /c start C:\temp\PSEXEC\PsExec.exe \\server -u username -p password cmd /c "cd /D c:\[temp folder] &echo call :execute_script>temp.bat &echo goto:eof>>temp.bat &echo :execute_script>>temp.bat &echo cd /D C:\BatchExecutors>>temp.bat &echo SnapExecutor.bat %%*>>temp.bat"

(这将创建批处理文件,然后您可以使用它来调用它:

    cmd /c start C:\temp\PSEXEC\PsExec.exe \\server -u username -p password cmd /c "C:\[temp folder]\temp.bat"

注意:

  • 将 [临时文件夹] 更改为远程 PC 上的可写文件夹。

关于windows - 从命令行执行远程 bat 文件时传递 Y/N,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39232664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com