解决bash脚本中的sys.excepthook错误
问题内容:
我编写了一个bash脚本,该脚本确实可以执行我想要的操作,但是会出现以下错误:
close failed in file object destructor: sys.excepthook is missing lost sys.stderr
我完全不知道如何解决这个问题。这是脚本:
#!/bin/bash
usage () { echo "${0##*/} inputfile outputfile"; exit 1; }
(($#==2)) || usage
INPUTFILE="$1"
OUTPUTFILE="$2"
# All that is written between between the 'cat' command and
#+ 'EOF' will be sent to the output file.
cat <<EOF >$OUTPUTFILE
$(date "+Generated on %m/%d/%y at %H:%M:%S")
DATA AUDIT: $1
------------
COLUMN NAMES
------------
$(csvcut -n $INPUTFILE)
---------------------------------------
FIRST TEN ROWS OF FIRST FIVE COLUMNS
---------------------------------------
$(csvcut -c 1,2,3,4,5 $INPUTFILE | head -n 10)
------------
COLUMN STATS
------------
$(csvcut $INPUTFILE | csvstat )
---END AUDIT
EOF
echo "Audited!"
我对shell脚本很陌生,对python也很陌生。我将不胜感激。
问题答案:
当将Python 2.6.2脚本的输出管道传输到Ubuntu
9.04上的head
命令时,我看到了此错误bash
。我添加了try
块以关闭stdout
并stderr
在退出脚本之前:
try:
sys.stdout.close()
except:
pass
try:
sys.stderr.close()
except:
pass
我不再看到错误。