Using Double Pipe in IF command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
WiVi71
Posts: 19
Joined: 06 Jan 2020 02:33

Using Double Pipe in IF command

#1 Post by WiVi71 » 19 Mar 2020 12:40

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..) :?:

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: Using Double Pipe in IF command

#2 Post by siberia-man » 19 Mar 2020 13:16

Batch syntax is extremely poor and doesn't support more complicated conditions.
You could try Conditionals on steroids which enables more benefits.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Using Double Pipe in IF command

#3 Post by penpen » 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

WiVi71
Posts: 19
Joined: 06 Jan 2020 02:33

Re: Using Double Pipe in IF command

#4 Post by WiVi71 » 21 Mar 2020 17:13

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.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Using Double Pipe in IF command

#5 Post by penpen » 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

WiVi71
Posts: 19
Joined: 06 Jan 2020 02:33

Re: Using Double Pipe in IF command

#6 Post by WiVi71 » 21 Mar 2020 19:35

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

Post Reply