goto in a one-line command
Moderator: DosItHelp
goto in a one-line command
Hi,
I was wondering if there was a way to define a label and use a goto to this one in a one-line command. I can't find a solution to this problem, I made several attempts but nothing seems to work.
Thank you in advance.
I was wondering if there was a way to define a label and use a goto to this one in a one-line command. I can't find a solution to this problem, I made several attempts but nothing seems to work.
Thank you in advance.
Re: goto in a one-line command
Your question doesn't make sense.
You want to define a label, so there must be code after the label, and somehow you want to jump to the routine.
If you can explain what you need to do it may become clearer.
You want to define a label, so there must be code after the label, and somehow you want to jump to the routine.
If you can explain what you need to do it may become clearer.
Re: goto in a one-line command
I'm just trying to make a while loop in a one-line command, no matter what the loop does.
Re: goto in a one-line command
It takes two lines. One to set the label and one to branch to the label.
:loop
goto :loop
:loop
goto :loop
Re: goto in a one-line command
thanks but i'm looking for a way to do it as a one-liner from the command line.
Re: goto in a one-line command
The same question arises: what are you trying to do?
Re: goto in a one-line command
Maybe this can help:
In this way I sometimes check the progress of a file copy operation or something (to see if certain file makes a progress - gains in file size).
Saso
Code: Select all
for /L %i IN (1,1,1000) do dir&&ping -n 5 -w 1 127.0.0.1>NUL&&cls
In this way I sometimes check the progress of a file copy operation or something (to see if certain file makes a progress - gains in file size).
Saso
Re: goto in a one-line command
foxidrive wrote:It takes two lines. One to set the label and one to branch to the label.
foxidrive wrote:You want to define a label, so there must be code after the label, and somehow you want to jump to the routine.
It's possible, but there is another problem
Code: Select all
<:label <nul echo endless loop? & goto :label
echo end
Output wrote:endless loop?
end
The cause is, that a jump or a call to a label will always set the execution position to the line AFTER the label.
So this can be useful with a CALL but not very useful with a GOTO.
The syntax of labels are described at Call a label as a variable
Or at Experiment with call and label
Btw. I'm using this to initialize my batchLibrary
jeb
Re: goto in a one-line command
jeb wrote:Code: Select all
<:label <nul echo endless loop? & goto :label
echo endOutput wrote:endless loop?
end
FWIW this produces the same output.
Code: Select all
@echo off
<:label <nul echo endless loop?
echo end
pause
Re: goto in a one-line command
Yes obviously, but you can see the difference if you change the GOTO with a CALL statement
jeb
Code: Select all
<:label <nul echo endless loop? & CALL :label & echo I'm in a label line
echo end "%0"
exit /b
Output wrote:endless loop?
end ":label"
I'm in a label line
end "test"
jeb
Re: goto in a one-line command
Yes, I see that jeb.
I really do wonder what the OP is trying to do on the command line though.
My thought is that a for-in-do might do what they want to do, but they aren't speaking.
I really do wonder what the OP is trying to do on the command line though.
My thought is that a for-in-do might do what they want to do, but they aren't speaking.