返回值不起作用 [英] Return value not working

查看:102
本文介绍了返回值不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我认为我有一个简单的问题.但是无法解决

我想做一件简单的事情:

档案1:
"one.bat":

Hi,
I think, I''ve got an easy problem.. but can''t solve it

I want to do a simple thing:

File 1:
"one.bat":

@echo off
echo One 
Two.bat
-------<here i="" want="" to="" get="" returned="" value...="">-------
echo The End
pause</here>



档案2:
"Two.bat":



File 2:
"Two.bat":

@echo off
echo Two 
-------<here i="" want="" to="" return="" value="">-------
</here>





我累了:
EXIT/B 23-无效..

[edit]已添加代码块,忽略HTML ..."选项已禁用-OriginalGriff [/edit]





I tired:
EXIT /B 23 - and doesn''t work..

[edit]Code blocks added, "Ignore HTML..." option disabled - OriginalGriff[/edit]

推荐答案

一段时间以来,我一直在玩这个游戏...

一.蝙蝠:
Been a while since I played with this...

one.Bat:
@echo off
echo one
call two.bat
if %errorlevel%==23 goto twentythree
echo unknown errolevel
goto end
:twentythree
echo Success!
:end



二.蝙蝠:



two.Bat:

@echo OFF
echo two
exit /B 23

如果仅从one.bat中执行two.bat,则它将在两个退出时返回CMD,而不是回到one.bat中的同一个目录-您需要使用CALL two.bat

If you just execute two.bat from within one.bat, then it will return to CMD when two exits, not to the same plave in one.bat - you need to use CALL two.bat


改为使用新的批处理功能:

Use new batch feature instead:

call:proc parameter
goto:eof

:proc
    echo %1
goto:eof



proc中的"goto:oef"行实际上并没有到达文件末尾,而是执行了返回操作. parameter的值在proc内部以%1的形式获得.

—SA



The line "goto:oef" in proc actually does not go to the end of file but performs a return. The value of parameter is obtained inside proc as %1.

—SA


这篇关于返回值不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆