我在子进程python中遇到错误FileNotFoundError: [WinError 2] The system cannot find the file specified
。我在堆栈溢出上搜索了它,但没有找到与我的情况相关的任何答案。基本上,我试图通过python代码计算视频的持续时间。我在堆栈溢出上搜索了它,找到了一段代码。当我试图执行这段代码时,我得到了FileNotFoundError: [WinError 2] The system cannot find the file specified
。我检查一个文件及其路径是否正确,文件是否正确。这是我试图运行的代码,我从here获得它
import subprocess
def get_length(filename):
result = subprocess.run(["ffprobe", "-v", "error", "-show_entries",
"format=duration", "-of",
"default=noprint_wrappers=1:nokey=1", filename],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return float(result.stdout)
get_length("video.avi")
如有任何建议,将不胜感激。以下是全部错误:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-17-8d1ce3720e37> in <module>
9 return float(result.stdout)
10
---> 11 get_length("video.avi")
<ipython-input-17-8d1ce3720e37> in get_length(filename)
6 "default=noprint_wrappers=1:nokey=1", filename],
7 stdout=subprocess.PIPE,
----> 8 stderr=subprocess.STDOUT)
9 return float(result.stdout)
10
~\Anaconda3\envs\FYP\lib\subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
421 kwargs['stdin'] = PIPE
422
--> 423 with Popen(*popenargs, **kwargs) as process:
424 try:
425 stdout, stderr = process.communicate(input, timeout=timeout)
~\Anaconda3\envs\FYP\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
727 c2pread, c2pwrite,
728 errread, errwrite,
--> 729 restore_signals, start_new_session)
730 except:
731 # Cleanup if the child failed starting.
~\Anaconda3\envs\FYP\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1015 env,
1016 os.fspath(cwd) if cwd is not None else None,
-> 1017 startupinfo)
1018 finally:
1019 # Child is launched. Close the parent's copy of those pipe
FileNotFoundError: [WinError 2] The system cannot find the file specified
我很困惑,为什么我会得到这个错误,虽然我的代码是完美的工作
import subprocess
process = subprocess.Popen(['vlc', 'video.avi'],
stdout=subprocess.PIPE,
universal_newlines=True)
目前没有回答
相关问题 更多 >
编程相关推荐