如何在cmd.exe的命令行参数中包含goto标签? [英] How do you include a goto label in a command line parameters for cmd.exe ?
本文介绍了如何在cmd.exe的命令行参数中包含goto标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何在传递给cmd.exe的命令字符串中包含goto label?
Does anyone know how can you include goto label in the command string passed to cmd.exe ?
有这样的情况:
cmd.exe /c ":retry & copy /y new_file.exe file.exe & if [%errorlevel%]==[1] goto :retry"
推荐答案
一个无限循环,并有成功后退出。我不知道我推荐这个,因为错误可能导致一个真正的无限循环。
You could accomplish your logic by putting your command in an infinite loop, and have it EXIT upon success. I'm not sure I recommend this, since an error could result in a truly infinite loop.
cmd.exe /c "for /l %N in () do @copy /y new_file.exe file.exe && exit"
我想你可以添加一个在N次失败尝试后退出的计数器。这是一个成功后立即退出的示例,如果失败3次也会退出。
I suppose you could add a counter that EXITs after N number of failed attempts. Here is an example that exits immediately upon success, and also exits if it fails 3 times.
cmd.exe /c "for /l %N in () do @copy /y new_file.exe file.exe && exit || >nul 2>&1 set /a 1/((failCnt+=1)%3) || exit"
这篇关于如何在cmd.exe的命令行参数中包含goto标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文