开发者

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. 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...

any help on this would be much appreciated ^_^

开发者_如何学运维

edit: sorry, here's the code :)

primary.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:

echo Working!
pause


You should either cd to the current directory in your first batch file or call the second batch file by full path.


Is the second .bat file in your path? What happens if you change your first .bat file to call it using an absolute path?


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


Absolute path may be replaced with %~dp0\, which means use current script's path instead of runtime context; in your case 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜