初学node.js,想完成这样的功能:
读取配置文件config.txt中相应的字段,追加到serverlist.json中。
我目前想用执行系统命令这样的方法取得 var serid = 'S1'; WanIp = exec("grep -w "+serid+" config.txt |awk {'print $2'}|awk -F/ {'print $1'}"); name = exec("grep -w "+serid+" config.txt |awk '{print $NF}' "); WanIp.stdout.on('data', function (ip) { console.log(ip); });
怎么样能把这个Wanip的变量,传到json参数中去呢?
var JsonObj = JSON.parse(fs.readFileSync('./test.json')); //console.log(JsonObj.appOnline[0]);