Conditional operators are operators useful allowing different commands to be interconnected. For example, using conditionnal operators a command can be executed only upon failure of another command.
command1 operator command2 ...
Run two commands linked by a conditional operator:
command1, command2 : Two valid Dos9 commands.
operator : An operator linking command1 and command2.
There is four types of conditional operators:
& : No condition. Command2 gets executed after command1.
This operator is not really interesting as the same result can be achieved by placing both commands on separates names (through the use of parenthesis for FOR and IF commands), achieving also a higher readability.
&& : Run command2 if command1 does not return any error. To determine if an error occured, Dos9 uses the value of the %ERRORLEVEL% variable fixed by command1 and :
if %ERRORLEVEL% is zero, then the command completed successfully.
else the command returned on error.
|| : Run command2 if command1 fails.
| : Connects command1 standard output to command2 standard input and run both simultaneously.
As both commands are executed simultaneously, the process Dos9 forks and a child interpreter is created. While command2 runs on the parent interpreter, command1 is executed on the child. Once command1 exits, the child interpreter dies and the script execution continues on the parent intepreter.
Thus, if a command1 modifies Dos9 environement variable, the changes will not affect the parent interpretor, and the environement of the parent will be left unchanged. As an example:
set example=1 | more test.txt
will not assign the %exemple% variable. However, command2 can actually change environment variables of the parent interpreter. As an example:
more test.txt | set /p example=
will assign the %example% variable.
This behaviour is the opposite of cmd.exe, but it seem more worthwhile to keep the current behaviour as it make possible to assign easily the outpout of a command to a variable.
Obviously, there is no limation in the number of conditional operators that can be used in a single line.
Available since 0.5.0.0.
Compatible with cmd.exe, except for the order of process in pipes.