programing

Powershell 스크립트에서 BAT 파일을 실행하는 가장 안전한 방법

nasanasas 2020. 11. 17. 08:09
반응형

Powershell 스크립트에서 BAT 파일을 실행하는 가장 안전한 방법


bat 파일을 직접 실행하는 powershell 스크립트를 얻을 수 없습니다. 예를 들어 다음은 명령 줄에서 작동합니다.

.\\my-app\my-fle.bat

이 명령을 스크립트에 추가하면 다음이 출력됩니다.

The term '.\\my-app\my-file.bat' is not recognized as the 
name of a cmdlet, function, script file, or operable program. 
Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.

나는 또한 동일한 결과로 다음을 시도했습니다.

& .\\my-app\my-fle.bat
& ".\\my-app\my-fle.bat"
\my-app\my-fle.bat
& \my-app\my-fle.bat
& "\my-app\my-fle.bat"

참고 : 일괄 처리의 성공 여부를 확인해야하므로 lastexitcode를 반환해야합니다.


cmd.exe /c '\my-app\my-file.bat'

.bat를 실행하고 마지막 종료 코드에 액세스하려면 다음과 같이 실행하십시오.

 & .\my-app\my-fle.bat

이것을 시도하십시오, 당신의 도트 소스가 약간 벗어났습니다. 편집, OP에 대한 lastexitcode 비트 추가.

$A = Start-Process -FilePath .\my-app\my-fle.bat -Wait -passthru;$a.ExitCode

-WindowStyle Hidden보이지 않는 배치를 위해 추가하십시오 .

참고 URL : https://stackoverflow.com/questions/20645326/safest-way-to-run-bat-file-from-powershell-script

반응형