Python 脚本从 Shell 文件启动时无法运行,但从终端启动时可以运行
如果我从终端启动 Google Code 上传 Python 脚本,它会按预期工作,但是当我在 Bourne Shell 脚本文件中使用下面的代码启动它时,它会失败并显示错误“close failed in file object destructor: Error”在 sys.excepthook 中:原始异常是:
”。
#!/bin/sh
BUILD_FOLDER="/Users/James/Documents/Xcode Projects/Uber Sweep - Mac/build/Release & Package"
if [ -f "$BUILD_FOLDER/Uber Sweep (64 bit).zip" ]; then
python /Users/James/Scripts/Google\ Code\ Upload.py -s "Uber Sweep - Mac OS X (64 bit)" -p "uber-sweep" -u "EXCLUDED" -l "Featured,Type-Archive,OpSys-OSX" "$BUILD_FOLDER/Uber Sweep (64 bit).zip" | echo
fi
这是为什么呢?
谢谢您的帮助,
jrtc27
If I launch the Google Code upload Python script from Terminal, it works as expected, but when I launch it using the code below in a Bourne Shell Script file, it fails with the error "close failed in file object destructor: Error in sys.excepthook: Original exception was:
".
#!/bin/sh
BUILD_FOLDER="/Users/James/Documents/Xcode Projects/Uber Sweep - Mac/build/Release & Package"
if [ -f "$BUILD_FOLDER/Uber Sweep (64 bit).zip" ]; then
python /Users/James/Scripts/Google\ Code\ Upload.py -s "Uber Sweep - Mac OS X (64 bit)" -p "uber-sweep" -u "EXCLUDED" -l "Featured,Type-Archive,OpSys-OSX" "$BUILD_FOLDER/Uber Sweep (64 bit).zip" | echo
fi
Why is this?
Thank you for your help,
jrtc27
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
echo 不接受来自标准输入的任何内容,因此它除了输出空行之外什么也不做。脚本的输出应该会出现,而无需对其进行任何操作。
尝试指定
python
的完整路径。脚本的PATH
可能与交互式 shell 的不同。您应该能够引用 Python 脚本的名称并避免尴尬的空格转义。
echo
doesn't accept anything from stdin, so it's doing nothing but outputting a blank line. The script's output should appear without having to do anything to it.Try specifying the full path to
python
. ThePATH
for the script may be different than it is for your interactive shell.You should be able to quote the name of your Python script and avoid the awkward escaping of spaces.