Powershell에서 배치 파일을 실행한 다음 열린 상태로 유지하려면 어떻게 해야 하나요?

StackOverflow https://stackoverflow.com/questions/14300

  •  08-06-2019
  •  | 
  •  

문제

예를 들어;이전 명령 프롬프트에서는 다음과 같습니다.

cmd.exe /k mybatchfile.bat
도움이 되었습니까?

해결책

cmd 인스턴스(또는 실제로는 PowerShell 자체)에 들어가서 다음을 입력합니다.

powershell -?

powershell.exe에는 "시작 명령"을 실행한 후에 종료하지 않도록 지시하는 "-noexit" 매개변수가 있음을 알 수 있습니다.

다른 팁

PowerShell.exe를 실행할 때 다음을 제공하세요. -출구 불가 다음과 같이 전환하세요:

PowerShell -NoExit -File "C:\SomeFolder\SomePowerShellScript.ps1"

PowerShell -NoExit -Command "Write-Host 'This window will stay open.'"

또는 파일을 실행한 다음 명령을 실행하고 창을 열어 두려면 다음과 같이 할 수 있습니다.

PowerShell -NoExit "& 'C:\SomeFolder\SomePowerShellScript.ps1'; Write-Host 'This window will stay open.'"

그만큼 -명령 제공되지 않은 경우 매개변수가 암시되며 여기서는 & PowerShell 스크립트를 호출하고 ; PowerShell 명령을 구분합니다.

또한 하단에는 내 블로그 게시물 스크립트/명령을 실행한 후에 항상 PowerShell을 열어 두어 항상 -NoExit 스위치를 명시적으로 제공할 필요가 없도록 할 수 있는 빠른 레지스트리 변경 방법을 보여 드리겠습니다.

이미 알고 계시겠지만 그냥 포스팅합니다

$CreateDate = (Get-Date -format 'yyyy-MM-dd hh-mm-ss')

$RemoteServerName ="server name"
$process = [WMICLASS]"\\$RemoteServerName\ROOT\CIMV2:win32_process"  
$result = $process.Create("C:\path to a script\test.bat") 
$result | out-file -file "C:\some path \Log-$CreatedDate.txt"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top