[英]can't call .bat file from within another - “not recognized as an internal or external command” error
i tried looking at the other questions regarding this, but no go.我尝试查看有关此的其他问题,但没有去。 i've tried a straight call to the other bat file ("otherBat.bat," for instance), a "call" command, and even a "start" command.
我试过直接调用另一个 bat 文件(例如“otherBat.bat”)、“call”命令,甚至是“start”命令。 all of these are failing though, and i'm at a loss as to why.
尽管如此,所有这些都失败了,我不知道为什么。 both .bat files are within the same folder, and i'm not changing directories, so i don't know what the problem is...
两个 .bat 文件都在同一个文件夹中,我没有改变目录,所以我不知道问题是什么......
any help on this would be much appreciated ^_^对此的任何帮助将不胜感激^_^
edit: sorry, here's the code :)编辑:对不起,这是代码:)
primary.bat:主要.bat:
echo Test run...enter variable1
set /p var1=:
echo Test run...enter variable2
set /p var2=:
call other.bat %var1% %var2%
pause
other.bat:其他.bat:
echo Working!
pause
您应该 cd 到第一个批处理文件中的当前目录,或者通过完整路径调用第二个批处理文件。
Is the second .bat file in your path?您的路径中是否有第二个 .bat 文件? What happens if you change your first .bat file to call it using an absolute path?
如果您更改第一个 .bat 文件以使用绝对路径调用它,会发生什么情况?
use the absolute path :使用绝对路径:
::prototype
CALL [drive:][path]filename [parameters]
::example
call C:\Users\theUserName\path-to-your-file\the-file-name.bat %your-variables-to-pass%
Absolute path may be replaced with %~dp0\\
, which means use current script's path instead of runtime context;绝对路径可以用
%~dp0\\
替换,这意味着使用当前脚本的路径而不是运行时上下文; in your case call %~dp0\\other.bat %var1% %var2%
.在你的情况下
call %~dp0\\other.bat %var1% %var2%
。
Had same issue when running as administrator from context menu – call
tried to execute batch file in System32 instead of parent BAT folder.从上下文菜单以管理员身份运行时遇到同样的问题 -
call
尝试在System32而不是父 BAT 文件夹中执行批处理文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.