imherer
V2EX  ›  Node.js

node exec win 乱码

  •  
  •   imherer · Jan 8, 2018 · 3391 views
    This topic created in 3073 days ago, the information mentioned may be changed or developed.

    最近有个需求在内网服务器上跑几个 ping 命令测试点东西 在 Mac 下写完测试了也问题,于是就丢服务器,服务器是 win 的,发现用 exec 执行完 ping 命令返回有乱码

    用 iconv-lite 尝试转 gbk 还是乱码

    各位前辈有遇到过吗?

    主要代码如下

    var exec = require('child_process').exec;
    exec('ping -c3 127.0.0.1', function (err, stdout, stderr) {
        console.log(stdout) // 这里在 win 下获得的值有乱码
    });
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5447 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 09:03 · PVG 17:03 · LAX 02:03 · JFK 05:03
    ♥ Do have faith in what you're doing.