首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ubuntu上的HandbrakeCLI与未找到文件的Python错误

Ubuntu上的HandbrakeCLI与未找到文件的Python错误
EN

Stack Overflow用户
提问于 2020-09-24 22:08:42
回答 1查看 289关注 0票数 0

我正试图用python3编写一个程序,在我的ubuntu机器上使用手制动来记录一些视频。

我错过了一些愚蠢的东西,但我无法为自己的生活找到答案,而且我已经做了无数个小时了。

下面是代码:

代码语言:javascript
复制
def convertvideo(input_file):
    hb_args = (" -i " + input_file + " -o " + handbraketempspace + " --preset-import-file "+handbrake_json_file_location + " -Z " + handbrake_profile_name)
    print (hb_args) # for debug only
    subprocess.Popen(handbrake + hb_args)
    return()

不管我如何重新排列“我得到两个错误之一,要么手制动器说文件找不到,要么它找不到我的预设。”

这个精确的命令在命令行中工作得很好。

以下是具体的错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "SubProcessing.py", line 161, in <module>
    finalvideo = convertvideo(sys.argv[2])
  File "SubProcessing.py", line 82, in convertvideo
    subprocess.Popen(handbrake + hb_args)
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: "/usr/bin/HandBrakeCLI -i /root/Alone-S02E01-Once_More_Unto_the_Breach_HDTV-720p.mkv -o /root/tmp/tempvideo.mkv --preset-import-file /mnt/media/PlexTestFiles/handbrake_presets.json -Z 'h.265_Hardware'"

提前谢谢你的帮助。再说一遍,我不是一个python程序员,但我不认为这会有这么难。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-24 22:16:54

您需要使用数组中的参数,而不是字符串来调用subprocess.Popen。就你的情况而言,有关部分将是:

代码语言:javascript
复制
subprocess.Popen([handbrake, "-i", input_file, "-o", handbraketempspace, "--preset-import-file", handbrake_json_file_location, "-Z", handbrake_profile_name])

或者,您可以将shell=True指定为subprocess.Popen,但这会不必要地启动一个shell,所以最好不要使用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64055093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档