문제

How would you implement logical operators in DOS Batch files?

도움이 되었습니까?

해결책

You can do and with nested conditions:

if %age% geq 2 (
    if %age% leq 12 (
        set class=child
    )
)

or:

if %age% geq 2 if %age% leq 12 set class=child

You can do or with a separate variable:

set res=F
if %hour% leq 6 set res=T
if %hour% geq 22 set res=T
if "%res%"=="T" (
    set state=asleep
)

다른 팁

The IF statement does not support logical operators (AND and OR), cascading IF statements make an implicit conjunction.

IF Exist File1.Dat IF Exist File2.Dat GOTO FILE12_EXIST_LABEL

If File1.Dat and File1.Dat exist then jump the label FILE12_EXIST_LABEL.

See also: IF /?

De Morgan's laws allow us to convert disjunctions ("OR") into logical equivalents using only conjunctions ("AND") and negations ("NOT"). This means we can chain disjunctions ("OR") on to one line.

This means if name is "Yakko" or "Wakko" or "Dot", then echo "Warner brother or sister".

set warner=true
if not "%name%"=="Yakko" if not "%name%"=="Wakko" if not "%name%"=="Dot" set warner=false
if "%warner%"=="true" echo Warner brother or sister

This is another version of paxdiablo's "OR" example, but the conditions are chained on to one line. (Note that the opposite of leq is gtr, and the opposite of geq is lss.)

set res=true
if %hour% gtr 6 if %hour% lss 22 set res=false
if "%res%"=="true" set state=asleep

The following examples show how to make an AND statement (used for setting variables or including parameters for a command).

To start Notepad and close the CMD window:

start notepad.exe & exit

To set variables x, y, and z to values if the variable 'a' equals blah.

IF "%a%"=="blah" (set x=1) & (set y=2) & (set z=3)

Hope that helps!

FFPLAY가 버전에서 버전으로 변경하지만 코드에서 IPC 코드와 이벤트가 SDL에서 개발 된 GUI로부터 수신되지 않습니다.따라서 ffplay.c에서 event_loop () 함수를 변경하려면 ffplay.c에서 stdin에서 이벤트를 가져오고 q 프로세스의 write () 메소드를 사용하여 이벤트를 전송할 수 있습니다.

main () 및 event_loop () 함수를 제거하는 자신의 클래스에서 FFPLAY 코드를 랩핑 할 수도 있습니다.

VS2012에서 코딩 된 UI 테스트를 찾는 것이 좋습니다.SharePoint 버전의 버전 인 경우에는 언급하지 않았으므로 2013 년이라고 가정합니다.

Microsoft SharePoint 2013에서 제공하는 모든 기능은 몇 가지 예외가있는 코드화 된 UI 테스트를 사용하여 테스트 할 수 있습니다.

이 기사를 살펴보십시오. 이는 시작하는 데 도움이 될 수 있습니다 : http://blogs.msdn.com/b/visualstudioalm/archive/2013/01/25/ui-testing-of-Microsoft-SharePoint-2013-with-Visual-Studio-2012.aspx

솔루션의 핵심 기능에 대한 작은 테스트 사례를 만드는 것입니다.나중에 확장하십시오.그것이 작고 모듈 식으로 만드는 것은 그것을 유지할 수있게 만듭니다.쉬운 함정 중 하나는 실제로 크고 테스트 케이스를 통해 나중에 변경하기가 어려울 것입니다.

행운

Athul Prakash (age 16 at the time) gave a logical idea for how to implement an OR test by negating the conditions in IF statements and then using the ELSE clause as the location to put the code that requires execution. I thought to myself that there are however two else clauses usually needed since he is suggesting using two IF statements, and so the executed code needs to be written twice. However, if a GOTO is used to skip past the required code, instead of writing ELSE clauses the code for execution only needs to be written once.

Here is a testable example of how I would implement Athul Prakash's negative logic to create an OR.

In my example, someone is allowed to drive a tank if they have a tank licence OR they are doing their military service. Enter true or false at the two prompts and you will be able to see whether the logic allows you to drive a tank.

@ECHO OFF
@SET /p tanklicence=tanklicence:
@SET /p militaryservice=militaryservice:

IF /I NOT %tanklicence%==true IF /I NOT %militaryservice%==true GOTO done

ECHO I am driving a tank with tanklicence set to %tanklicence% and militaryservice set to %militaryservice%

:done

PAUSE

It's just as easy as the following:

AND> if+if

if "%VAR1%"=="VALUE" if "%VAR2%"=="VALUE" *do something*

OR> if // if

set BOTH=0
if "%VAR1%"=="VALUE" if "%VAR2%"=="VALUE" set BOTH=1
if "%BOTH%"=="0" if "%VAR1%"=="VALUE" *do something*
if "%BOTH%"=="0" if "%VAR2%"=="VALUE" *do something*

I know that there are other answers, but I think that the mine is more simple, so more easy to understand. Hope this helps you! ;)

If you have interested to write an if+AND/OR in one statement, then there is no any of it. But, you can still group if with &&/|| and (/) statements to achieve that you want in one line w/o any additional variables and w/o if-else block duplication (single echo command for TRUE and FALSE code sections):

@echo off

setlocal

set "A=1" & set "B=2" & call :IF_AND
set "A=1" & set "B=3" & call :IF_AND
set "A=2" & set "B=2" & call :IF_AND
set "A=2" & set "B=3" & call :IF_AND

echo.

set "A=1" & set "B=2" & call :IF_OR
set "A=1" & set "B=3" & call :IF_OR
set "A=2" & set "B=2" & call :IF_OR
set "A=2" & set "B=3" & call :IF_OR

exit /b 0

:IF_OR
( ( if %A% EQU 1 ( type nul>nul ) else type 2>nul ) || ( if %B% EQU 2 ( type nul>nul ) else type 2>nul ) || ( echo.FALSE-& type 2>nul ) ) && echo TRUE+

exit /b 0

:IF_AND
( ( if %A% EQU 1 ( type nul>nul ) else type 2>nul ) && ( if %B% EQU 2 ( type nul>nul ) else type 2>nul ) && echo.TRUE+ ) || echo.FALSE-


exit /b 0

Output:

TRUE+
FALSE-
FALSE-
FALSE-

TRUE+
TRUE+
TRUE+
FALSE-

The trick is in the type command which drops/sets the errorlevel and so handles the way to the next command.

Internet Explorer가 다른 브라우저에서 다르게 자동 완성 포커스 이벤트를 처리하는지 확인한 경우;본질적으로 IE는 비동기 적으로 이벤트를 수행하며,이 때문에 이벤트가 발생한 이벤트 순서를 신속하게 결정할 수 없었습니다.기본적으로, 내가해야 할 일은이 작은 코드를 선택한 이벤트에 추가했습니다.

select: function(event, ui) {
  $this = $(this);
  setTimeout(function() {
    $("#<%=txtBoss.ClientID %>").val(ui.item.boss);
    $this.blur();
  }, 1);
}
.

나는 이것을 매우 멋지게 설명하는 훌륭한 기사를 발견했다 : http://daniellang.net/blur-not-working-with-jquery-ui-autocomplete-in-ie//a>

Slight modification to Andry's answer, reducing duplicate type commands:

set "A=1" & set "B=2" & call :IF_AND
set "A=1" & set "B=3" & call :IF_AND
set "A=2" & set "B=2" & call :IF_AND
set "A=2" & set "B=3" & call :IF_AND

echo.

set "A=1" & set "B=2" & call :IF_OR
set "A=1" & set "B=3" & call :IF_OR
set "A=2" & set "B=2" & call :IF_OR
set "A=2" & set "B=3" & call :IF_OR

goto :eof

:IF_OR

(if /i not %A% EQU 1 (
   if /i not %B% EQU 2 (
      echo FALSE-
      type 2>nul
   )
)) && echo TRUE+

goto :eof

:IF_AND


(if /i %A% EQU 1 (
   if /i %B% EQU 2 (
      echo TRUE+
      type 2>nul
   )
)) && echo FALSE-

goto :eof
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top