dongyou8701
2014-06-07 04:44
浏览 93
已采纳

PowerShell上的输出流用于SSH调用

My PHP script (in Linux) is not printing my values on screen, however it prints a Warning message.

e.g.

This is my php code:

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

This is my powershell code:

Write-Warning "This is a test"

And this is what PHP is writing:

Powershell output: WARNING: You should update your PowerShell to PowerShell 2.0 version.

QUESTION: How can I catch the the stream returned by Powershell?

图片转代码服务由CSDN问答提供 功能建议

我的PHP脚本(在Linux中)没有在屏幕上打印我的值,但是它会打印一条警告消息。

例如

这是我的PHP代码:

  $ stream = ssh2_exec($ connection,'  powershell“c:
emoteScript.ps1” -  $ NotificationID“5359f76f888ddf35b889dedf”'); 
 $ string = stream_get_contents($ stream); 
echo“Powershell输出:”。  $ string; 
   
 
 

这是我的powershell代码:

  Write-Warning“这是一个测试”  n   
 
 

这就是PHP编写的内容:

Powershell输出:警告:您应该更新PowerShell to PowerShell 2.0版本。

问题:如何捕获Powershell返回的流?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtl4521 2014-06-07 12:42
    已采纳

    SOLUTION: we need to tell ssh2_exec whether to wait/block until the remote process finishes search for "block" on this page to see an example.

    $stream = ssh2_exec($connection, 'powershell \'C:\scriptsemoteVeeamClientSummary.ps1\' -Client \''. $Client. '\' -NotificationID \''. $NotificationID. '\'');
    
    stream_set_blocking($stream, true);
    
    return stream_get_contents($stream);
    

    and powershell:

    Write-Output $result
    
    点赞 打赏 评论

相关推荐 更多相似问题