将脚本的 stdout/stderr 与命令本身以及 time 命令的结果 stderr 一起重定向到文件
我的链命令:mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py;
- 将
myscript.py
的stdout
和stderr
重定向到log.txt
。
$ mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1 | tee log.txt
$ cat log.txt
stdout and stderr are shown here.
- 将 chain 命令插入到
log.txt
的开头。
$ echo 'mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1' | tee log.txt | bash >> log.txt
$ cat log.txt
mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1
stdout and stderr are shown here.
- 对命令进行计时
$ (time python3 mydir/myscript.py) 2> log.txt
$ cat log.txt
real 0m0,302s
user 0m0,003s
sys 0m0,001s
我的问题是如何连接上面的 3 项,使 log.txt
看起来像
mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1
stdout and stderr are shown here.
real 0m0,302s
user 0m0,003s
sys 0m0,001s
谢谢。
My chain command: mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py;
- Redirect
stdout
andstderr
ofmyscript.py
tolog.txt
.
$ mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1 | tee log.txt
$ cat log.txt
stdout and stderr are shown here.
- Insert the chain command to the beginning of
log.txt
.
$ echo 'mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1' | tee log.txt | bash >> log.txt
$ cat log.txt
mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1
stdout and stderr are shown here.
- Time the command
$ (time python3 mydir/myscript.py) 2> log.txt
$ cat log.txt
real 0m0,302s
user 0m0,003s
sys 0m0,001s
My question is how to concatenate 3 items above so the log.txt
looks like
mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1
stdout and stderr are shown here.
real 0m0,302s
user 0m0,003s
sys 0m0,001s
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一些尝试和错误后,我认为以下代码是有效的。
After some tries and errors, I think the following code is working.