Powershell编码不能随shell_exec更改,但它可以从console或ps1文件更改,为什么?

时间:2017-08-26 07:31:31

标签: php powershell encoding utf-8

我有 powershell版本5.1 。我想从PowerShell中获取一些来自powershell的报告,其中 shell_exec ,并且在网页上显示。因为resports可能包含非英语单词,我想将powershell的编码更改为UTF8以支持其他语言。我在我的powershell脚本(.ps1文件)中使用此代码,并且编码确实改变了:

[Console]::OutputEncoding = New-Object -typename System.Text.UTF8Encoding

但是我想用我的php文件用 shell_exec 运行这个脚本。当我在我的php文件中运行此命令时:

shell_exec($PowershellPath . '[Console]::OutputEncoding = New-Object -typename System.Text.UTF8Encoding');

我在网页上看到 [Console] :: OutputEncoding 我看到编码没有改变但是当我在powershell控制台中获得[Console] :: OutputEncoding时,我看到编码改变了是真的,是utf8。

我认为这个问题与从外部来源进行更改的权限有关,或者[控制台]只是更改控制台编码

任何人都可以帮我用shell_exec更改powershell的编码吗?

0 个答案:

没有答案