I am having trouble getting the output from a python script, that I didn't write, redirected to grep. Below are my experiments including the base cases. "myPythonCmd" is long running and streams to stdout.
Any suggestions?
/myPythonCmd.py arg1 arg2
Outputs both stderr and stdout to the screen
/myPythonCmd.py arg1 arg2 2>/dev/null
Outputs just stdout to the screen
/myPythonCmd.py arg1 arg2 2>/dev/null > outputfile
Outputs nothing to the screen, but writes stdout to outputfile
/myPythonCmd.py arg1 arg2 2>/dev/null | grep searchTerm
Outputs NOTHING even though I know searchTerm is present.
/myPythonCmd.py arg1 arg2 2>/dev/null | grep --line-buffered searchTerm
Outputs NOTHING even though I know searchTerm is present.
python's -u option is what was needed. Thanks @PM_2Ring
python -u myPythonCmd.py arg1 arg2 2>/dev/null | grep searchTerm
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.