child.bat未被识别为内部或外部命令、可操作程序或批处理文件



我遇到了一个bat文件问题。

我正在调用主bat文件中的一个bat文件。两个bat文件位于同一文件夹中,即"D:\"

测试.bat:

SET str=HELLO
ECHO say %str% Test
Call Child.bat

Child.bat:

ECHO say %str% child 

Test.bat文件中,我声明了一个变量str,并在子bat文件中使用它。当我通过双击直接运行Test.bat时,它按预期工作,我会得到结果

say HELLO Test
say HELLO Child

但问题是,如果我在命令提示符下从另一台机器运行Test.bat文件作为

  • 开放式跑步
  • 输入//服务器/D$/Test.bat

它只执行Test.bat,当我得到类似的输出时,无法调用Child.bat

say HELLO Test
Child.bat not recognized as an internal or external command, operable program or batch file

在上面的命令提示符上,我可以看到一条类似的语句

'\ServerD$' CMD.EXE was started with the above path as the current directory. UNC paths are not supported.  Defaulting to Windows directory.

实际上,我需要设置一个sql作业来调用Test.bat文件。

我该如何解决此问题?

test.bat

pushd "%~dp0"
SET str=HELLO
ECHO say %str% Test
Call Child.bat
popd

只需创建一个临时映射并将当前文件夹更改为它。最后释放它。pushd /popd将处理它。

但是,当它工作时,如果调用批处理文件时,当前活动目录是UNC路径(从windows run对话框调用它时会发生什么),则会显示UNC错误。如果您想避免这种情况,请确保启动进程时默认使用不同的目录。

相关内容

最新更新