0

It's a simple script I wrote, nothing fancy at all

@echo off

echo 1 = stream1 source
echo 2 = stream1 high
echo 3 = stream1 medium
echo 4 = stream1 low
echo 5 = stream2 source
echo 6 = stream2 high
echo 7 = stream2 medium
echo 8 = stream2 low

set /p id="Enter ID: "

IF %id% == 1 (
    set link=twitch.tv/stream1 source
) ELSE IF %id% == 2 (
    set link=twitch.tv/stream1 high
) ELSE IF %id% == 3 (
    set link=twitch.tv/stream1 medium
) ELSE IF %id% == 4 (
    set link=twitch.tv/stream1 low
) ELSE IF %id% == 5 (
    set link=twitch.tv/stream2 source
) ELSE IF %id% == 6 (
    set link=twitch.tv/stream2 high
) ELSE IF %id% == 7 (
    set link=twitch.tv/stream2 medium
) ELSE IF %id% == 8 (
    set link=twitch.tv/stream1 high
) ELSE (
echo ..............
echo 1 = source
echo 2 = high
echo 3 = medium
echo 4 = low

set /p quality="Enter ID: "

    IF %quality% == 1 (
        set hq="source"
    ) ELSE IF %quality% == 2 (
        set hq="high"
    ) ELSE IF %quality% == 3 (
        set hq="medium"
    ) ELSE IF %quality% == 4 (
        set hq="low"
    ) ELSE (
        set hq="source"
    )
    set link=twitch.tv/%id% %hq%
)

Start C:\livestreamer\livestreamer.exe %link%

echo %link%

pause

What it does is ask for a number 1-8, if it's 1-8 it'll run the program livestream.exe with command line stream1 source, stream2 source, etc depending on what the user input.

If it's not 1-8, then the program asks for the quality, so source/high/medium/low.

For example, if they put in 1, then the command that'll finally be run is

Start C:\livestreamer\livestreamer.exe stream1 source

If 2,

Start C:\livestreamer\livestreamer.exe stream1 high

etc

If they put in for example asdfasdf

then put in high, then the final will be

Start C:\livestreamer\livestreamer.exe asdfasdf high

It works if i remove the stuff inside the final else condition, but otherwise it doesn't :(

The error I'm getting is

( was unexpected at this time.

2 Answers 2

0

It appears that you need to change your %id% == 1 type statements to the form of "%id%"=="1".

When the macro variable (e.g., %id%) is set to a space it is expanded to: IF space == 1 ( which isn't valid syntax. But if you surround the macro variable with some set of characters (I usually use double quotes) the statement is expanded to IF "space" == 1 ( which is valid syntax but doesn't conform to your intentions. To get it to work, you need to surround the comparison value with the same character (in this case, double quotes).

IF "%id%"=="1"

IF "%id%"=="1" (
    set link=twitch.tv/stream1 source
) ELSE IF "%id%"=="2" (
    set link=twitch.tv/stream1 high
) ELSE IF "%id%"=="3" (
    set link=twitch.tv/stream1 medium
...

    IF "%quality%"=="1" (
        set hq="source"
    ) ELSE IF "%quality%"=="2" (
        set hq="high"
    ...
0

The line that's failing is the IF %quality% == 1.

While the batch file logically only executes the nested If in the one branch, the entire If statement is processed as one command, and so the whole command must be valid, in all branches. Your If statement (as a whole) is not valid at time of processing.

If you enable Echo, you'll see the line fail as

( was unexpected at this time.
C:\Temp>    IF  == 1 (

Note the part that failed: IF == 1 (.

This is invalid because there's no left side to the comparison. There's no left side of the comparison because the set to assign a value to the quality variable wasn't executed before the If was processed (since it's nested within the If).

A fix:

Enclose both sides of all comparisons with quotes, so that an empty value will be "" instead of just a space.

E.g.:

IF "%id%" == "1" (
    set link=twitch.tv/stream1 source
) ELSE IF "%id%" == "2" (
    set link=twitch.tv/stream1 high
) ELSE IF "%id%" == "3" (
    set link=twitch.tv/stream1 medium
) ELSE IF "%id%" == "4" (
    set link=twitch.tv/stream1 low
) ELSE IF "%id%" == "5" (
    set link=twitch.tv/stream2 source
) ELSE IF "%id%" == "6" (
    set link=twitch.tv/stream2 high
) ELSE IF "%id%" == "7" (
    set link=twitch.tv/stream2 medium
) ELSE IF "%id%" == "8" (
    set link=twitch.tv/stream1 high
) ELSE (...

Another Fix:

Move the nested If into it's own labelled section, and use Goto statements to direct flow.

@echo off

echo 1 = stream1 source
echo 2 = stream1 high
echo 3 = stream1 medium
echo 4 = stream1 low
echo 5 = stream2 source
echo 6 = stream2 high
echo 7 = stream2 medium
echo 8 = stream2 low

set /p id="Enter ID: "

IF %id% == 1 (
    set link=twitch.tv/stream1 source
) ELSE IF %id% == 2 (
    set link=twitch.tv/stream1 high
) ELSE IF %id% == 3 (
    set link=twitch.tv/stream1 medium
) ELSE IF %id% == 4 (
    set link=twitch.tv/stream1 low
) ELSE IF %id% == 5 (
    set link=twitch.tv/stream2 source
) ELSE IF %id% == 6 (
    set link=twitch.tv/stream2 high
) ELSE IF %id% == 7 (
    set link=twitch.tv/stream2 medium
) ELSE IF %id% == 8 (
    set link=twitch.tv/stream1 high
) ELSE (
    goto ChooseQuality
)

goto StartProgram


:ChooseQuality

echo ..............
echo 1 = source
echo 2 = high
echo 3 = medium
echo 4 = low

set /p quality="Enter ID: "

IF %quality% == 1 (
    set hq="source"
) ELSE IF %quality% == 2 (
    set hq="high"
) ELSE IF %quality% == 3 (
    set hq="medium"
) ELSE IF %quality% == 4 (
    set hq="low"
) ELSE (
    set hq="source"
)
set link=twitch.tv/%id% %hq%

goto StartProgram


:StartProgram

Start C:\livestreamer\livestreamer.exe %link%

echo %link%

pause

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .