在运行sh.exec('whoami')
时,我尝试比较标准输出,但它不起作用。
我想要做的是,在运行whoami
命令之后,如果结果是一个特定的用户,那么我想触发一个操作。
在运行时,
sh.exec('whoami', (code, output) => {
sh.echo(output == 'myusername'); // False
console.log(output == 'myusername'); // False
});
条件output == 'myusername'
的计算结果为false,即使我完全确定它是真的,因为我已经复制了用户名并将其作为比较字符串。
预期的结果将是条件的计算结果为true。
发布于 2019-04-27 01:47:29
正在做,
console.log(sh.exec('whoami'));
您将获得以下输出,
{ [String: 'username\n']
stdout: 'username\n',
stderr: '',
code: 0,
cat: [Function: bound ],
exec: [Function: bound ],
grep: [Function: bound ],
head: [Function: bound ],
sed: [Function: bound ],
sort: [Function: bound ],
tail: [Function: bound ],
to: [Function: bound ],
toEnd: [Function: bound ],
uniq: [Function: bound ]
}
问题只是一条新的路线。stdout
在末尾附带了一个\n
。
https://stackoverflow.com/questions/55872298
复制相似问题