简体   繁体   English

无法从另一个内部调用 .bat 文件 - “未识别为内部或外部命令”错误

[英]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%

cf the call documentation from ss64.com参见ss64.com 的通话文档

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.

相关问题 bat文件令牌或for循环出错:未被识别为内部或外部命令,可操作程序或批处理文件 - Error with bat file token or for loop: not recognized as an internal or external command, operable program or batch file 路径具有git,但我的bat文件不断说“ git”未被识别为内部或外部命令 - Path has git but my bat file keep saying 'git' is not recognized as an internal or external command my.bat未被识别为内部或外部命令,可操作程序或批处理文件 - my.bat not recognized as an internal or external command, operable program or batch file 使用 Powershell 运行 a.bat 脚本时避免“不被识别为内部或外部命令” - Avoiding “is not recognized as an internal or external command” when running a .bat script with Powershell 错误:“cat”未被识别为内部或外部命令 - Error : 'cat' is not recognized as an internal or external command cmd错误:“ ANT”未被识别为内部或外部命令 - cmd error: 'ANT' is not recognized as an internal or external command $不被识别为内部或外部命令 - $ is not recognized as an internal or external command '$'不被识别为内部或外部命令 - '$' is not recognized as an internal or external command '和'不被视为内部或外部命令 - 'and' is not recognized as an internal or external command 从同一文件夹中调用另一个 .bat 文件? - Call another .bat file from within the same folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM