Page 1 of 1

Using Double Pipe in IF command

Posted: 19 Mar 2020 12:40
by WiVi71
I'm trying to use a double pipe or double ampersand in IF command, but it doesn't work as I expected.

Code: Select all

> IF . EQU , DISM || ECHO POO
|| is not expected
This does not work.

Code: Select all

> IF . EQU , (DISM || ECHO POO)
|| is not expected
This does not work either.

Code: Select all

> IF . EQU , DISM ||(ECHO POO)
> IF . EQU , ('DISM || ECHO POO')
> IF . EQU , ("DISM || ECHO POO")
> IF . EQU , ('"DISM || ECHO POO"')
> IF . EQU , DISM^
MORE?> || ECHO POO
> IF . EQU , DISM^
MORE?> (|| ECHO POO)
> IF . EQU , DISM ||^
These codes also do not work.
Is there any other way to use a double pipe or a double empersend in the IF command (without using IF %ERRORLEVEL% NEQ..) :?:

Re: Using Double Pipe in IF command

Posted: 19 Mar 2020 13:16
by siberia-man
Batch syntax is extremely poor and doesn't support more complicated conditions.
You could try Conditionals on steroids which enables more benefits.

Re: Using Double Pipe in IF command

Posted: 19 Mar 2020 17:39
by penpen
I don't think, that WiVi71 tries to use the conditional-execution operator "||" as a conditional-OR operator.

@WiVi71
In all the examples you gave, you have used the character COMMA (',').
That character is a delimiter and must be escaped, so the following might help you:

Code: Select all

IF . EQU ^, DISM || ECHO POO
IF "." EQU "," DISM || ECHO POO
penpen

Re: Using Double Pipe in IF command

Posted: 21 Mar 2020 17:13
by WiVi71
penpen wrote:
19 Mar 2020 17:39
I don't think, that WiVi71 tries to use the conditional-execution operator "||" as a conditional-OR operator.

@WiVi71
In all the examples you gave, you have used the character COMMA (',').
That character is a delimiter and must be escaped, so the following might help you:

Code: Select all

IF . EQU ^, DISM || ECHO POO
IF "." EQU "," DISM || ECHO POO
penpen
Thanks! I didn't know if "," needed escape.
Also, FOR /F %A IN ('"ECHO WOW"') DO (TIMEOUT 1 && ECHO WOW || ECHO OHH) Worked.

Re: Using Double Pipe in IF command

Posted: 21 Mar 2020 18:20
by penpen
WiVi71 wrote:
21 Mar 2020 17:13
Also, FOR /F %A IN ('"ECHO WOW"') DO (TIMEOUT 1 && ECHO WOW || ECHO OHH) Worked.
I don't see any reason for the for-loop of that command, just use pure conditional-chaining ("&&") and conditional-execution operator ("||"):

Code: Select all

TIMEOUT 1 && ECHO WOW || ECHO OHH
I'm also not fully sure how that for-loop is connected to siberia-man's or my post.

penpen

Re: Using Double Pipe in IF command

Posted: 21 Mar 2020 19:35
by WiVi71
penpen wrote:
21 Mar 2020 18:20
WiVi71 wrote:
21 Mar 2020 17:13
Also, FOR /F %A IN ('"ECHO WOW"') DO (TIMEOUT 1 && ECHO WOW || ECHO OHH) Worked.
I don't see any reason for the for-loop of that command, just use pure conditional-chaining ("&&") and conditional-execution operator ("||"):

Code: Select all

TIMEOUT 1 && ECHO WOW || ECHO OHH
I'm also not fully sure how that for-loop is connected to siberia-man's or my post.

penpen
The article was just an example(And I confused the IF command question with the FOR command question :/); the scripts to actually use were:

Code: Select all

:Making_Folder
IF NOT EXIST "%~DP0Projects\" MD "%~DP0Projects" || GOTO ERROR
IF NOT EXIST "%~DP0Projects\Temp\" MD "%~DP0Projects\Temp" || GOTO ERROR
IF NOT EXIST "%~DP0Projects\Output\" MD "%~DP0Projects\Output" || GOTO ERROR
IF NOT EXIST "%~DP0Projects\Packages\" MD "%~DP0Projects\Packages" || GOTO ERROR

:ERROR
ECHO ⓘ Error occurred during Folder Generation
ECHO - Move batch file to another directory
ECHO ERROR CODE : 201
EXIT /B