2017-11-24 51 views
0

私が必要とするのは、text/htmlというテキストをCLIでクリップボードにコピーしてから、utf-8 Webページのリッチテキストエディタに貼り付けます。しかし、chcpを使用してエンコードを変更したにもかかわらず、サイリック文字のエンコードに問題があります。cmd、Power Shell、またはその両方のエンコーディングの問題

これは、(それ自体があまりにもUTF-8エンコーディングを持っているもちろん、ファイルの).ps1というファイルがどのように見えるかです:

chcp 65001 
$args[0] | Set-Clipboard -AsHtml 

実行chcp 65001(UTF-8)とCMDからスクリプトやキリル文字パラメータ:

chcp 65001 
powershell C:\Users\admin\go.ps1 "КИРИЛЛИЦА IS CYRILLIC" 

コマンド出力:

enter image description here

enter image description here

+0

は、なぜあなたは '-AsHtml'を使用していますか? – TheIncorrigible1

+0

テキストを "text/html"形式でコピーしてリッチテキストボックスに貼り付ける必要があるので、 –

+0

なぜですか?それがあなたの問題の原因です。 – TheIncorrigible1

答えて

0

BUG: Set-Clipboard -AsHtml puts invalid CF_HTML on clipboard with non-ASCII text

Blake Coverettの回避策は、このに噛ま他の誰のための

Function StringToEntities ($aux) { 
    ## https://windowsserver.uservoice.com/users/307215574-blake-coverett 
    ($aux.ToCharArray() | ForEach-Object { 
     $codePoint = [int]$_ 
     if ($codePoint -ge 127) { 
      "&#$codePoint;" 
     } else { 
      $_ 
     } 
    }) -join '' 
} 

'buggy' 
$args[0] | Set-Clipboard -AsHtml 
Get-Clipboard -TextFormatType Html | Where-Object {$_ -match 'body'} 
'workaround' 
StringToEntities($args[0]) | Set-Clipboard -AsHtml 
Get-Clipboard -TextFormatType Html | Where-Object {$_ -match 'body'} 

私は私が手にリッチテキストエディタに貼り付けるとの問題がここにありますサンプル出力(デバッグ用です。 )cmdコードページは関係ないことを示しています

https://html-online.com/editor/で試験
==> chcp 
Active code page: 852 

==> powershell -noprofile D:\PShell\SO\47474346.ps1 "'КИРИЛЛИЦА IS CYRILLIC, ελληνικά is Greek'" 

buggy 
<html><body><!--StartFragment-->????????? IS CYRILLIC, ???????? is Greek<!--EndFragment--></body 
></html> 
workaround 
<html><body><!--StartFragment-->&#1050;&#1048;&#1056;&#1048;&#1051;&#1051;&#1048;&#1062;&#1040; 
IS CYRILLIC, &#949;&#955;&#955;&#951;&#957;&#953;&#954;&#940; is Greek<!--EndFragment--></body>< 
/html> 

==> 

pasted HTML clipboard

関連する問題