Windows在subprocess.call()上找不到文件 [英] Windows can't find the file on subprocess.call()

查看:492
本文介绍了Windows在subprocess.call()上找不到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下错误:

WindowsError: [Error 2] The system cannot find the file specified

我的代码是:

subprocess.call(["<<executable file found in PATH>>"])

Windows 7,64位.最新的Python 3.x,稳定.

Windows 7, 64 bit. Python 3.x latest, stable.

有什么想法吗?

谢谢

推荐答案

当命令是内置的shell时,请在调用中添加"shell = True".

When the command is a shell built-in, add a 'shell=True' to the call.

例如对于dir,您将输入:

import subprocess
subprocess.call('dir', shell=True)

要引用文档中的内容:

在Windows上唯一需要指定shell = True的时间是将要执行的命令内置到shell中(例如dir或copy).您不需要shell = True即可运行批处理文件或基于控制台的可执行文件.

The only time you need to specify shell=True on Windows is when the command you wish to execute is built into the shell (e.g. dir or copy). You do not need shell=True to run a batch file or console-based executable.

这篇关于Windows在subprocess.call()上找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆