2014-06-07 4 views
0

내 PHP 스크립트 (Linux)가 내 값을 화면에 인쇄하지 않지만 경고 메시지를 인쇄합니다.SSH 호출을위한 powershell의 출력 스트림

예컨대 이 내 파워 쉘 코드

$stream = ssh2_exec($connection, 'powershell "c:\remoteScript.ps1" -$NotificationID "5359f76f888ddf35b889dedf"'); 
$string = stream_get_contents($stream); 
echo "Powershell output: ". $string; 

:

내 PHP 코드

Write-Warning "This is a test" 

그리고 이것은 PHP가 쓰는 것입니다 :

파워 쉘 출력 : 경고 : PowerShell을 PowerShell 2.0 버전으로 업데이트해야합니다.

는 질문 : 어떻게 파워 쉘에 의해 반환 된 스트림을 잡을 수 있습니까?

+0

당신은 아마 PowerShell을 적어도 2.0를 업데이트 시작해야는 1.0 구식 거의 오년입니다 –

답변

0

해결 방법 : 원격 프로세스가 완료 될 때까지 대기/차단할지 여부를 ssh2_exec에 알려야합니다. search for "block" on this page to see an example.

$stream = ssh2_exec($connection, 'powershell \'C:\scripts\remoteVeeamClientSummary.ps1\' -Client \''. $Client. '\' -NotificationID \''. $NotificationID. '\''); 

stream_set_blocking($stream, true); 

return stream_get_contents($stream); 

및 파워 쉘 :

Write-Output $result