Skip to content

已知问题

¥Known Issues

输出被截断

¥Output gets truncated

这是 console.log() 的一个已知问题(请参阅 nodejs/node#6379)。这是由 console.log() 写入终端和文件的不同行为引起的。如果进程调用 process.exit(),缓冲的输出将被截断。为了防止这种情况,进程应该使用 process.exitCode = 1 并等待进程自行退出。或者使用 exit 包之类的东西。

¥This is a known issue with console.log() (see nodejs/node#6379). It's caused by different behaviour of console.log() writing to the terminal vs to a file. If a process calls process.exit(), buffered output will be truncated. To prevent this, the process should use process.exitCode = 1 and wait for the process to exit itself. Or use something like exit package.

解决方法是写入临时文件:

¥Workaround is to write to a temp file:

js
const tmp = await $`mktemp` // Creates a temp file.
const {stdout} = await $`cmd > ${tmp}; cat ${tmp}`

子流程中的颜色

¥Colors in subprocess

与你在终端中看到的相比,你可能会看到使用 await $ 调用的工具不显示颜色。这是因为,子进程不认为它是 TTY 并且子进程关闭颜色。通常有一种方法强制子进程添加颜色。

¥You may see what tools invoked with await $ don't show colors, compared to what you see in a terminal. This is because, the subprocess does not think it's a TTY and the subprocess turns off colors. Usually there is a way force the subprocess to add colors.

js
process.env.FORCE_COLOR='1'
await $`cmd`

google/zx 中文网 - 粤ICP备13048890号