node.js - 使用分离屏幕模式记录 nodejs 输出
问题描述
我有这个脚本,我想为其记录输出。
for i in {1..20}
do
sleep 2
echo "Running Bot $i"
screen -dm node testbot.js test localhost 4 > $i.txt
done
日志文件被创建,但没有任何内容被放入其中。当我在 shell 中单独运行它们时,它可以工作:
node testbot.js test localhost 4 > test.txt
但它不适用于分离的屏幕。我也尝试了这种变化:
screen -dm node testbot.js test localhost 4 | tee $i.txt
但它也没有用。testbot.js 里面只有一些 console.log() 语句。
我该怎么做才能将输出输出到日志文件中?
解决方案
我自己解决了这个问题。我修改了脚本,现在正在记录输出。
for i in {1..20}
do
sleep 2
echo "Running Bot $i"
logfile="$i.txt"
export logfile
screen -mdS bot$i bash -c 'node testbot.js test localhost 4 &> $logfile'
done
推荐阅读
- python - Python列表理解太慢了
- angular - Angular 6:Http升级
- c++ - “'CLOCK_PER_SEC' 未在此范围内声明”错误,即使包含
- android - Android Studio 3.2 Preview 中的导航预览不可用
- arrays - 插入嵌套数组
- javascript - 试图在前端显示信息
- aws-lambda - Kinesis:异常:SocketException:不允许操作(选择/轮询失败)
- java - 如何在 Gradle 中获取生命周期库的版本?
- php - 使用 Post 将课程发送到另一个页面
- python - 如何将 pip 版本 10.0.0 降级到 pip 版本 9.0.1?