如何执行脚本从 nodejs 设置 iterm2 徽章?

How to exec script to set iterm2 Badge from nodejs?

我从 Iterm2 官方网站得到这个 bash 脚本。

printf "\e]1337;SetBadgeFormat=%s\a" $(echo "text" | base64)

我试过像下面这样执行,没有错误,但未能设置 iterm2 徽章

var exec = require('child_process').exec;
exec('printf "\e]1337;SetBadgeFormat=%s\a" $(echo "text" | base64)');

setBadgeFormat.js =>

#!/usr/bin/env node

var rawBadgeFormat = 'test'
var base64BadgeFormat = new Buffer(rawBadgeFormat).toString('base64')
var setBadgeFormatCmd = 'printf "\e]1337;SetBadgeFormat=' + base64BadgeFormat + '\a"'
require('child_process').exec(setBadgeFormatCmd, function(error, stdout, stderr) {
    if (error) console.log(error);
    process.stdout.write(stdout); // this line actually do the trick
    process.stderr.write(stderr);
});