Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > How to make goto when nowhere to go ?

Reply
Thread Tools Display Modes

How to make goto when nowhere to go ?

 
 
Synapse Syndrome [KGB]
Guest
Posts: n/a

 
      06-13-2009
(NT shell scripting)

Say I have a goto parameter command -

goto :%parm%

If the batch label does not exist, the script ends with the error:

"The system cannot find the batch label specified - whatever"

I do not want the error message displayed, and I want the script to go and
do something else instead. If I try..

goto :%parm:~2% || goto :error

...that does not work.

Any solution?

Cheers

ss.


 
Reply With Quote
 
 
 
 
Al Dunbar
Guest
Posts: n/a

 
      06-13-2009

"Synapse Syndrome [KGB]" <> wrote in message
news:eG0tC$...
> (NT shell scripting)
>
> Say I have a goto parameter command -
>
> goto :%parm%
>
> If the batch label does not exist, the script ends with the error:
>
> "The system cannot find the batch label specified - whatever"
>
> I do not want the error message displayed, and I want the script to go and
> do something else instead. If I try..
>
> goto :%parm:~2% || goto :error
>
> ..that does not work.
>
> Any solution?


NT shell scripting, on what O/S: nt3.51, nt4, w2k, w2k3, w2k8, xp?

I don't think you can trap an attempt to go to an invalid label. The
alternative is to check the value of the parm variable to see if it is a
valid label. One way:

do %%L in (label1 label2 label3) if "%parm%" EQU "%%L" goto:%parm%

Another way would be to use FIND or FINDSTR to search the batch file for
instances of ":%parm%". Trouble is if there was a "label called ":whatsit"
and the value of parm was "what"...

/Al


 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      06-13-2009

"Synapse Syndrome [KGB]" <> wrote in message
news:eG0tC$...
> (NT shell scripting)
>
> Say I have a goto parameter command -
>
> goto :%parm%
>
> If the batch label does not exist, the script ends with the error:
>
> "The system cannot find the batch label specified - whatever"
>
> I do not want the error message displayed, and I want the script to go and
> do something else instead. If I try..
>
> goto :%parm:~2% || goto :error
>
> ..that does not work.
>
> Any solution?
>
> Cheers
>
> ss.


If you want your batch file to be robust then you must check if the
parameter passed to it is a valid label. Relying on some internal error
capturing process is not good a programming technique. You could do it like
this:

@echo off
set Labels=/one/two/three/twenty/
if not "%1"=="" echo %Labels% | find /i "/%1/" > nul || echo Invalid label

Make sure to surround each label name with a forward slash and not to use
any labels with embedded forward slashes.


 
Reply With Quote
 
Al Dunbar
Guest
Posts: n/a

 
      06-13-2009

"T Lavedas" <> wrote in message
news:a34a7562-8512-4d0f-bf96-...
> On Jun 12, 11:46 pm, "Al Dunbar" <aland...@hotmail.com> wrote:
>> "Synapse Syndrome [KGB]" <syna...@NOSPAMsyndrome.me.uk> wrote in
>> messagenews:eG0tC$. ..
>>
>>
>>
>> > (NT shell scripting)

>>
>> > Say I have a goto parameter command -

>>
>> > goto :%parm%

>>
>> > If the batch label does not exist, the script ends with the error:

>>
>> > "The system cannot find the batch label specified - whatever"

>>
>> > I do not want the error message displayed, and I want the script to go
>> > and
>> > do something else instead. If I try..

>>
>> > goto :%parm:~2% || goto :error

>>
>> > ..that does not work.

>>
>> > Any solution?

>>
>> NT shell scripting, on what O/S: nt3.51, nt4, w2k, w2k3, w2k8, xp?
>>
>> I don't think you can trap an attempt to go to an invalid label. The
>> alternative is to check the value of the parm variable to see if it is a
>> valid label. One way:
>>
>> do %%L in (label1 label2 label3) if "%parm%" EQU "%%L" goto:%parm%
>>
>> Another way would be to use FIND or FINDSTR to search the batch file for
>> instances of ":%parm%". Trouble is if there was a "label called
>> ":whatsit"
>> and the value of parm was "what"...
>>
>> /Al

>
> Your batch skills are a bit rusty, Al. That should be ...
>
> FOR %%L in (label1 label2 label3) DO if "%parm%" EQU "%%L" goto:%parm
> %
>
> Tom Lavedas
> **************


Yeah, I always forget the DO. Fortunately, that throws an error which
reminds me. So thanks for being the error message in this case ;-)

/Al


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Just replace BUS!="usb*", GOTO="libgphoto2_rules_end" with "SUBSYSTEM!="usb_device", GOTO="libgphoto2_rules_end" luisortizhome@yahoo.com Windows Vista General Discussion 3 09-10-2007 06:46 AM
Is there an add-in to right-click/goto a URL that is not in an anchor tag? JJ Internet Explorer 1 03-08-2007 04:15 PM
Goto on vbscript Jrex7 Scripting 4 11-08-2005 01:11 PM
GOTO or Sub stev379 Scripting 0 08-17-2004 12:49 PM
Goto Unexpected at this time ??? scott ocamb Scripting 0 08-12-2003 01:02 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59