gpt4 book ai didi

Python执行windows cmd函数

转载 作者:可可西里 更新时间:2023-11-01 09:52:52 34 4
gpt4 key购买 nike

我知道您可以使用子进程通过 Python 脚本运行 Linux 终端命令

subprocess.call(['ls', '-l'])    # for linux

但是我找不到在windows上做同样事情的方法

subprocess.call(['dir'])         # for windows

是否可以在不进行大量修改的情况下使用 Python?

我应该坚持使用老式的批处理文件吗?

最佳答案

dir 不是一个文件,它是一个内部命令,所以 shell 关键字必须设置为 True。

subprocess.call(["dir"], shell=True)

关于Python执行windows cmd函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29925978/

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