gpt4 book ai didi

python - 解决 bash 脚本中的 sys.excepthook 错误

转载 作者:太空狗 更新时间:2023-10-29 20:36:47 24 4
gpt4 key购买 nike

我写了一个 bash 脚本,它正在做我想要它做的事情,但踢出以下错误:

在文件对象析构函数中关闭失败:sys.excepthook 丢失丢失 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 的新手。如果有任何帮助,我将不胜感激。

最佳答案

当我在 Ubuntu 9.04 上将 Python 2.6.2 脚本的输出通过管道传输到 bash 中的 head 命令时,我看到了这个错误。我添加了 try block 以在退出脚本之前关闭 stdoutstderr:

try:
sys.stdout.close()
except:
pass
try:
sys.stderr.close()
except:
pass

我不再看到错误。

关于python - 解决 bash 脚本中的 sys.excepthook 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7955138/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com