Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 从命令行执行远程bat文件时传递Y/N_Windows_Batch File_Batch Processing_Psexec - Fatal编程技术网

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

Windows 从命令行执行远程bat文件时传递Y/N,windows,batch-file,batch-processing,psexec,Windows,Batch File,Batch Processing,Psexec,我正在尝试执行远程批处理文件。我可以使用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 哪个人口问题 我想从命令中处理这个问题,如下所示: cmd /c sta

我正在尝试执行远程批处理文件。我可以使用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
哪个人口问题

我想从命令中处理这个问题,如下所示:

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

欢迎提出建议。提前感谢。

当两个批处理文件具有相同标签时,您可以使用奇怪的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上的[temp folder]更改为可写文件夹

您是否可以修改批处理文件?如果可以,您可以使用附加的输入参数调用该批处理文件,以便在设置输入参数时绕过该问题。否。我们不允许更改批处理文件。
cmd/c start c:\temp\PSEXEC\PSEXEC.exe\\server-u username-p password cmd/c(^cd C:\BatchExecutors^&echo y^ | SnapExecutor.bat位置^)
?为什么第一个(和最后一个)carret?我想
(^
部分应该是
^(
)。。。