在bash脚本处理sys.excepthook错误 [英] Addressing sys.excepthook error in bash script
问题描述
我写的是做正是我想要它做一个bash脚本,但蹬出以下错误:
I've written a bash script that is doing exactly what I want it to do, but kicking out the following error:
关闭失败的文件对象的析构函数:sys.excepthook丢失丢失sys.stderr来
我完全就如何解决这个问题难住了。下面是脚本:
I'm completely stumped on how to address this. Here is the script:
#!/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!"
我是pretty新的shell脚本和很新的蟒蛇。我会感谢任何帮助。
I am pretty new to shell scripts and very new to python. I would be grateful for any help.
推荐答案
这是一个Python管道输出时2.6.2脚本到的头,我看到这个错误
命令庆典
在Ubuntu 9.04。我加了尝试
块,收标准输出
和标准错误
退出前脚本:
I was seeing this error when piping output from a Python 2.6.2 script into the head
command in bash
on Ubuntu 9.04. I added try
blocks to close stdout
and stderr
before exiting the script:
try:
sys.stdout.close()
except:
pass
try:
sys.stderr.close()
except:
pass
我不再看到的错误。
I am no longer seeing the error.
这篇关于在bash脚本处理sys.excepthook错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!