Node.js exec和stdout的怪异行为

时间:2018-11-03 10:42:02

标签: javascript node.js boolean exec

我正在尝试将stdout中的String转换为Boolean。

有人可以向我解释为什么这段代码返回false而不是true

const { exec } = require('child_process')

exec('echo true', {}, (err, stdout) => {
    const current = stdout.toString();

    console.log(typeof current, current) // <- It returns: string true

    const status = (current === 'true');

    console.log(status); // <- I echoed true, I checked for true and instead I'm getting false
})

https://repl.it/@michelem09/WeirdStdout

0 个答案:

没有答案
相关问题