gpt4 book ai didi

Python 使用 windows 命令行

转载 作者:行者123 更新时间:2023-12-04 23:26:15 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





os.system doesn't work in Python

(2 个回答)



Why does not os.system("cd mydir") work and we have to use os.chdir("mydir") instead in python? [duplicate]

(3 个回答)



Python os.system() call runs in incorrect directory

(3 个回答)



Command line execution in different folder

(3 个回答)


4年前关闭。




我有这个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') 我不会收到错误消息。
我的代码有什么问题?

最佳答案

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

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

关于Python 使用 windows 命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46513100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com