让Python命令行输出从bash脚本调用时 [英] Get Python command line output when called from a bash script
问题描述
这可能是一个非常简单的问题。我通过shell脚本调用的Lubuntu OS(Cubietruck)Python脚本。这是自动启动的时候(我想保持这一进程)的进程。是否有可以查看在Python输出一个简单的方法?目前,Python脚本在后台运行,没有终端。我需要检查一些错误。该脚本是:
This may be a super simple question. I am calling a Python script on an Lubuntu OS (Cubietruck) via a shell script. This is to automate the process on start up (I want to maintain this process). Is there a simple way to view the output from Python? At the moment the Python script runs in the background, with no terminal. I have some errors that need checking. The script is:
#!/bin/sh
python recordSound.py
先谢谢了。
推荐答案
的妥善解决,可能会使用的 登录
所提出的意见。
The proper solution would probably use logging
as proposed in a comment.
在此期间,你必须重定向的两个的标准的输出的,为了捕捉到正常输出为壁标准的错误的流由脚本报告的错误:
In the meantime, you have to redirect both the standard output and the standard error stream in order to capture the normal output as wall as any error reported by your script:
#!/bin/sh
python recordSound.py >> logfile.log 2&>1
请参阅有关该主题的中的许多网页的一个探索从一个shell脚本的各种重定向。
See one of the many web pages on that topic to explore the various redirection available from a shell script.
此外,如果您需要同时登录的和的控制台上实时取景,使用的 T恤
标准的命令:
In addition, if you need both login and live view on the console, use the tee
standard command:
#!/bin/sh
python recordSound.py 2&>1 | tee logfile.log
这篇关于让Python命令行输出从bash脚本调用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!