我有一个bash脚本,它在Python脚本的末尾被调用。如果我用一个简单的Python脚本(下面的test.py)手动调用该脚本,它就可以正常工作。然而,当从我的实际脚本(long.py)调用时,它失败了。因此long.py
运行,在末尾调用rename.sh
,并向其传递一个linux目录路径source_dirrename.sh
重命名所述路径中的文件。以下是该脚本的相关摘录:
long.py
PATH = '/var/bigbluebutton/published/presentation/'
LOGS = '/var/log/bigbluebutton/download/'
source_dir = PATH + meetingId + "/"
...
def main():
...
try:
create_slideshow(dictionary, length, slideshow, bbb_version)
ffmpeg.trim_audio_start(dictionary, length, audio, audio_trimmed)
ffmpeg.mux_slideshow_audio(slideshow, audio_trimmed, result)
serve_webcams()
# zipdir('./download/')
copy_mp4(result, source_dir + meetingId + '.mp4')
finally:
print >> sys.stderr, source_dir
#PROBLEM LINE
subprocess.check_call(["/scripts/./rename.sh", str(source_dir)])
print >> sys.stderr, "Cleaning up temp files..."
cleanup()
print >> sys.stderr, "Done"
if __name__ == "__main__":
main()
问题是:
long.py
使用上述行调用rename.sh
:
subprocess.check_call(["/scripts/./rename.sh", str(source_dir)])
它给出了错误:
subprocess.CalledProcessError: Command '['/scripts/./rename.sh', '/var/bigbluebutton/published/presentation/5b64bdbe09fdefcc3004c987f22f163ca846f1ea-1574708322765/']' returned non-zero exit status 1
否则,脚本工作得很好
test.py是long.py的缩短版本,仅包含以下两行:
test.py
source_dir = '/var/bigbluebutton/published/presentation/5b64bdbe09fdefcc3004c987f22f163ca846f1ea-1574708322765/'
subprocess.check_call(["/scripts/./rename.sh", str(source_dir)])
当使用python test.py运行时,它不会遇到错误
以下是rename.sh的内容:
rename.sh
#!/bin/bash
i=$1
a=$(grep '<name>' $i/metadata.xml | sed -e 's/<name>\(.*\)<\/name>/\1/' | tr -d ' ')
b=$(grep '<meetingName>' $i/metadata.xml | sed -e 's/<meetingName>\(.*\)<\/meetingName>/\1/' | tr -d ' ')
c=$(ls -alF $i/*.mp4 | awk '{ gsub(":", "_"); print $6"-"$7"-"$8 }')
d=$(echo $b)_$(echo $c).mp4
cp $i/*.mp4 /root/mp4s/$d
test.py
和long.py
在同一位置
我没有手动执行long.py
;它被另一个程序执行
print >> sys.stderr, source_dir
确认long.py将与我在test.py中显式定义的值完全相同的值传递给rename.sh
目前没有回答
相关问题 更多 >
编程相关推荐