2012-06-15 11 views
0

나는 Powershell 명령을 DOS 프롬프트를 통해 실행하고 있는데, 명령을 실행하기 전에 PowerShell이 ​​먼저 설치되었는지 확인하고 싶습니다. PowerShell이 ​​실제 오류를 표시하지 않고 존재하지 않으면 스크립트를 종료하고 싶습니다. 여기 내 스크립트입니다 : 나는 데DOS Return ErrorLevel with Running Program

@echo off 
setlocal enabledelayedexpansion 
:: Check to see if Powershell is installed 
powershell.exe -command {"test"} > NUL 
if errorlevel 1 (
    echo/Powershell is NOT Installed 
    EXIT 
) else (
    goto PSI 
) 

:PSI 
powershell Set-ExecutionPolicy RemoteSigned 

문제는 내가 출력으로이납니다 있다는 것입니다 :

Powershell is NOT Installed 

'powershell.exe' is not recognized as an internal or external command, 
operable program or batch file. 

답변

1

그것을 알아 냈어! 출력을 리디렉션하기 위해 NUL 대신 2> NUL을 사용해야했습니다.

:: Check to See if Powershell is Installed 
powershell.exe test 2>NUL 
    if errorlevel 1 (
     echo/Powershell is NOT Installed 
    EXIT 
    ) else (
    goto PSI 
    ) 
+0

실제로 위의 powershell 명령도 오류가 발생합니다. PowerShell "Write-Output"n "2> NUL을 사용해야했습니다. –