code

CALL 명령 대 /WAIT 옵션으로 시작

starcafe 2023. 6. 2. 20:40
반응형

CALL 명령 대 /WAIT 옵션으로 시작

WAIT 옵션이 있는 START 명령은 어떻게 됩니까?

START /wait notepad.exe 
START /wait  notepad.exe 

...CALL 명령을 사용하는 것과 다른 점이 있습니까?

CALL notepad.exe 
CALL notepad.exe 

실행되는 것에 따라 다른 것과 다르게 행동할 수 있는 상황이 있습니까?

exe 파일의 경우 차이점은 거의 중요하지 않은 것 같습니다.
하지만 EXE를 시작하기 위해 필요하지도 않은CALL.

큰 가 납니다.
~하듯이CALL에서는 이 작업을 동일한 창에서 시작하고 호출된 배치는 동일한 변수 컨텍스트에 액세스할 수 있습니다.
따라서 발신자에게 영향을 미치는 변수도 변경할 수 있습니다.

START호출된 배치에 대해 새 cmd.exe를 생성하고 /b를 지정하지 않으면 새 창이 열립니다.
새로운 컨텍스트이기 때문에 변수를 공유할 수 없습니다.

차이점.

용사를 합니다.start /wait <prog>
환경 변수의 변경 사항은 다음과 같은 경우에 손실됩니다.<prog>
호출자는 다음 시간까지 기다립니다.<prog>되었습니다.

용사를 합니다.call <prog>
시작하는 과 동일하기 때문에 exe의 경우 생략할 수 있습니다.<prog>
exe 프로그램의 경우 호출자 배치는 비동기식으로 exe를 대기하거나 시작하지만 동작은 exe 자체에 따라 다릅니다.
배치 파일의 경우 호출자 배치는 호출된 경우 계속됩니다.<batch-file>하지 않으면 .

부록:

용사를 합니다.CALL에서는 매개 변수(배치 및 exe 파일)를 변경할 수 있지만 매개 변수에 캐럿 또는 퍼센트 기호가 포함된 경우에만 변경할 수 있습니다.

call myProg param1 param^^2 "param^3" %%path%%

(배치 파일 내에서)로 확장됩니다.

myProg param1 param2 param^^3 <content of path>

저는 그들이 일반적으로 동일한 성능을 발휘해야 한다고 생각하지만, 약간의 차이가 있습니다. START일반적으로 응용 프로그램을 시작하거나 지정된 파일 형식의 기본 응용 프로그램을 시작하는 데 사용됩니다.만약 당신이 그런 식으로START http://mywebsite.com그렇지 않습니다START iexplore.exe http://mywebsite.com.

START myworddoc.docxMicrosoft Word를 시작하고 내 worddoc.docx를 엽니다.CALL myworddoc.docx같은 일을...START에서는 창 상태 및 해당 속성에 대한 추가 옵션을 제공합니다.또한 프로세스 우선 순위 및 선호도를 설정할 수 있습니다.

간단히 말해서, 시작할 때 제공되는 추가 옵션을 고려할 때, 그것은 당신이 선택한 도구가 되어야 합니다.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
  [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
  [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
  [command/program] [parameters]

"title"     Title to display in window title bar.
path        Starting directory.
B           Start application without creating a new window. The
            application has ^C handling ignored. Unless the application
            enables ^C processing, ^Break is the only way to interrupt
            the application.
I           The new environment will be the original environment passed
            to the cmd.exe and not the current environment.
MIN         Start window minimized.
MAX         Start window maximized.
SEPARATE    Start 16-bit Windows program in separate memory space.
SHARED      Start 16-bit Windows program in shared memory space.
LOW         Start application in the IDLE priority class.
NORMAL      Start application in the NORMAL priority class.
HIGH        Start application in the HIGH priority class.
REALTIME    Start application in the REALTIME priority class.
ABOVENORMAL Start application in the ABOVENORMAL priority class.
BELOWNORMAL Start application in the BELOWNORMAL priority class.
NODE        Specifies the preferred Non-Uniform Memory Architecture (NUMA)
            node as a decimal integer.
AFFINITY    Specifies the processor affinity mask as a hexadecimal number.
            The process is restricted to running on these processors.

            The affinity mask is interpreted differently when /AFFINITY and
            /NODE are combined.  Specify the affinity mask as if the NUMA
            node's processor mask is right shifted to begin at bit zero.
            The process is restricted to running on those processors in
            common between the specified affinity mask and the NUMA node.
            If no processors are in common, the process is restricted to
            running on the specified NUMA node.
WAIT        Start application and wait for it to terminate.

사이에는 유용한 차이가 있습니다.call그리고.start /wait을 부를 때.regsvr32.exe /s예를 들어, Gary가 how-do-i-get-the-application-exit-code-from-a-windows-command-line에 대한 답변에서 언급했습니다.

call regsvr32.exe /s broken.dll
echo %errorlevel%

항상 0을 반환하지만

start /wait regsvr32.exe /s broken.dll
echo %errorlevel%

regsvr32.exe의 오류 수준을 반환합니다.

이것은 배치 파일을 병렬로 실행하는 동안 발견한 것입니다(다른 입력 매개 변수를 가진 동일한 bat 파일의 여러 인스턴스).

LongRunningTask.exe라는 긴 태스크를 수행하는 exe 파일이 있다고 가정해 보겠습니다.

bat 파일에서 exe를 직접 호출하면 LongRunningTask에 대한 첫 번째 호출만 성공하고 나머지는 "File is already using by process"라는 OS 오류 메시지가 표시됩니다.

이 명령을 사용하는 경우:

start /B/WAIT " " "LongRunningTask.exe" "파라미터"

배트가 나머지 명령을 계속 실행하기 전에 작업이 완료될 때까지 기다리는 동안 배트와 exe의 여러 인스턴스를 실행할 수 있습니다./B 옵션은 다른 창을 만들지 않도록 하는 것입니다. 명령이 작동하려면 빈 따옴표가 필요합니다. 아래 참조를 참조하십시오.

시작할 때 /WAIT를 사용하지 않으면 LongRunningTask가 배치 파일의 나머지 명령과 동시에 실행되므로 이러한 명령 중 하나에 LongRunningTask의 출력이 필요할 경우 문제가 발생할 수 있습니다.

다시 시작하는 중:

병렬로 실행할 수 없습니다.

  • LongRunningTask.exe 호출

이것은 병렬로 실행되며 명령 출력과 나머지 bat 파일 사이에 데이터 종속성이 없는 한 문제가 없습니다.

  • start /B " ""LongRunningTask.exe" "파라미터"

이 작업은 병렬로 실행되고 작업이 완료될 때까지 대기하므로 다음 출력을 사용할 수 있습니다.

  • start /B/WAIT " " "LongRunningTask.exe" "파라미터"

시작 명령에 대한 참조: 프로그램 시작 후 콘솔을 열어 두지 않고 배치 파일에서 프로그램을 실행하려면 어떻게 해야 합니까?

불러

상위 배치 프로그램을 중지하지 않고 다른 배치 프로그램에서 한 배치 프로그램을 호출합니다.호출 명령은 레이블을 호출 대상으로 수락합니다.스크립트 또는 배치 파일 외부에서 사용할 경우 명령줄에서 호출이 수행되지 않습니다.https://technet.microsoft.com/en-us/library/bb490873.aspx

시작

별도의 명령 프롬프트 창을 시작하여 지정된 프로그램 또는 명령을 실행합니다.매개 변수 없이 사용되는 start는 두 번째 명령 프롬프트 창을 엽니다.https://technet.microsoft.com/en-us/library/bb491005.aspx

언급URL : https://stackoverflow.com/questions/13257571/call-command-vs-start-with-wait-option

반응형