python - 如何在 Python 中使用 dir/s 命令?

标签 python windows python-2.7 subprocess

背景

我一直在批处理文件中使用命令 dir/s。但是,我无法使用 python 调用它。 注意:我使用的是 Python 2.7.3。

代码

import subprocess
subprocess.call(["dir/s"])

错误信息

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    subprocess.call(["dir/s"])
  File "C:\Python27\lib\subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

我试过更改引号,但没有任何效果。

如何使用 subprocess 调用 dir/s 模块?

最佳答案

怎么样

subprocess.call("dir/s", shell=True)

未验证。

关于python - 如何在 Python 中使用 dir/s 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15207271/

相关文章:

python - Python 是否可以检测文件是否已被移动?

python - 为什么我们必须创建一个新组来对 Odoo v8 中的所有用户隐藏菜单项?

Windows 上 Linux 的 C++ 编译器?

windows - Url 重写不会安装在 Windows 10 IIS 10 上

python - 导入错误: No module named queue

python - 从文本文件创建字典

python - 在 python 3.5.1 中混合关键字和默认参数

c++ - win32 API编程问题

mysql - 如果 Slave 关闭,Django 多个数据库回退到 Master

python - 如何使用脚本将标准输出重定向到文件和控制台?