none
コマンドwmicで型番を抽出してテキストに書き出し RRS feed

  • 質問

  • こんにちは。
    PCの型番ごとに処理を変更したく以下のようにバッチファイルを作成しています。

    wmic csproduct get Name>MODEL.txt
    findstr "EPSON" MODEL.txt

    としても正しく認識されません。
    wmic csproduct get Name

    では EPSON TJ66Eなどと表示されています。

    MODEL.txtを確認すると
    E P S O N
    と余計な空白?が入ってしまいます。

    findstr /C:"E P S O N" MODEL.txt

    としてもダメなようで、どうも空白では無くNULL文字というものらしい事までは確認できました。
    しかもUTF-16扱い??

    findstrではこのNULL文字をどのように認識させればよいのでしょうか?
    可能であれば
    findstr "EPSON" MODEL.txt
    で実行したいのですが・・・

    2019年12月25日 2:11

回答

  • wmic csproduct get Name > model.txt
    で生成されるファイルは、Visual Studio Code で確認すると、
    Encode:UTF-16 LE 改行:CRLF でした。
    findstr コマンドは UTF-16 ファイルを扱えないとの記事もあります。
    find コマンドは大丈夫です。
    https://kotaeta.com/70869476

    なので、以下のものに変更しては如何ですか?。

    wmic csproduct get Name | findstr "EPSON" > model.txt
    type model.txt

    或いは、

    wmic csproduct get Name > model.txt
    find "EPSON" model.txt | find "----" /V

    冗長ですが、

    wmic csproduct get Name > model.txt
    find "EPSON" model.txt | findstr "EPSON"


    • 編集済み ShiroYuki_Mot 2019年12月25日 4:23 誤字訂正 LF > LE
    • 回答としてマーク pipora 2019年12月25日 5:38
    2019年12月25日 3:29
  • パイプを通せばよろしいかと

    wmic csproduct get Name > model.txt
    type model.txt | findstr "EPSON"
    
    または
    
    wmic csproduct get Name | findstr "EPSON"
    
    念のため
    
    wmic csproduct get Name | findstr /i /c:"EPSON"
    

    • 回答としてマーク pipora 2019年12月25日 5:37
    2019年12月25日 3:46

すべての返信

  • wmic csproduct get Name > model.txt
    で生成されるファイルは、Visual Studio Code で確認すると、
    Encode:UTF-16 LE 改行:CRLF でした。
    findstr コマンドは UTF-16 ファイルを扱えないとの記事もあります。
    find コマンドは大丈夫です。
    https://kotaeta.com/70869476

    なので、以下のものに変更しては如何ですか?。

    wmic csproduct get Name | findstr "EPSON" > model.txt
    type model.txt

    或いは、

    wmic csproduct get Name > model.txt
    find "EPSON" model.txt | find "----" /V

    冗長ですが、

    wmic csproduct get Name > model.txt
    find "EPSON" model.txt | findstr "EPSON"


    • 編集済み ShiroYuki_Mot 2019年12月25日 4:23 誤字訂正 LF > LE
    • 回答としてマーク pipora 2019年12月25日 5:38
    2019年12月25日 3:29
  • パイプを通せばよろしいかと

    wmic csproduct get Name > model.txt
    type model.txt | findstr "EPSON"
    
    または
    
    wmic csproduct get Name | findstr "EPSON"
    
    念のため
    
    wmic csproduct get Name | findstr /i /c:"EPSON"
    

    • 回答としてマーク pipora 2019年12月25日 5:37
    2019年12月25日 3:46
  • お二人ともありがとうございます。

    パイプを通してバッチリ出来ました。

    2019年12月27日 0:53