下面一个为我工作 -
$ node a.js 1>stdout.log 2>stderr.log ; cat stdout.log stderr.log >> all.log
a.js
console.log('Hello World');
演示 stdout -
root@a2980bfaeb16:/# node a.js 1>stdout.log 2>stderr.log ; cat stdout.log stderr.log >> all.log
root@a2980bfaeb16:/# cat stdout.log
Hello World
root@a2980bfaeb16:/# cat stderr.log
root@a2980bfaeb16:/# cat all.log
Hello World
演示 stderr (犯了一个愚蠢的错误,看看它是否适用于 stderr ) -
root@a2980bfaeb16:/# node a.js 1>stdout.log 2>stderr.log ; cat stdout.log stderr.log >> all.log
root@a2980bfaeb16:/# cat stdout.log
root@a2980bfaeb16:/# cat stderr.log
/a.js:1
(function (exports, require, module, __filename, __dirname) { console.g('Hello World');
^
TypeError: console.g is not a function
at Object. (/a.js:1:71)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:618:3
root@a2980bfaeb16:/# cat all.log
Hello World
/a.js:1
(function (exports, require, module, __filename, __dirname) { console.g('Hello World');
^
TypeError: console.g is not a function
at Object. (/a.js:1:71)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:618:3
希望能帮助到你!
PS - 我试图将重定向与管道集成,但还没有运气 .