【问题标题】:Python using windows command line [duplicate]Python使用Windows命令行[重复]
【发布时间】:2017-10-01 13:58:03
【问题描述】:

我有这个 python 代码:

        import os
        os.system('cd C:\yt')
        os.system("ffmpeg.exe -i test.mp4 newfilename.mp3")

yt 文件夹包括 ffmeg.exe 和 test.mp4,但我在 cmd 上将代码分开编写,一切正常,但因此我收到以下错误消息:

       'ffmpeg.exe' is not recognized as an internal or external command,
       operable program or batch file.

如果我使用 C:\yt\ffmpeg.exe -i test.mp4 newfilename.mp3 不起作用,如果我只使用 os.system('cd C:\yt') 我不会收到错误消息。 我的代码有什么问题?

【问题讨论】:

  • os.system在子shell中执行命令,也就是说第二条命令不在C:\yt中执行
  • 我重新修改:subprocess.call("ffmpeg.exe -i test.mp4 newfilename.mp3",cwd=r"c:\yt")

标签: python cmd ffmpeg


【解决方案1】:

您需要移动到该目录。请尝试以下操作:

import os
os.chdir('C:\yt')
print os.getcwd() # confirm location
os.system("ffmpeg.exe -i test.mp4 newfilename.mp3")

【讨论】:

  • 在单独的目录中运行命令确实是一种糟糕的方式。
  • 我正在遵循 OPs 方法
  • 我知道,但有时最好不要这样做,或者解释一下然后提供更好的方法。
猜你喜欢
  • 2014-07-18
  • 1970-01-01
  • 2012-10-29
  • 2010-10-03
  • 2016-10-12
  • 2021-09-18
  • 2013-01-31
  • 2013-07-01
  • 1970-01-01
相关资源
最近更新 更多