子进程给出一个错误. “系统找不到指定的文件". [英] subprocess gives an error. "The system cannot find the file specified"

查看:473
本文介绍了子进程给出一个错误. “系统找不到指定的文件".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

import urllib
import requests

from bs4 import *
from subprocess import Popen,PIPE
import os

connectString = 'SYSTEM/mediadot123'

def runSqlQuery(sqlCommand, connectString):
   session = Popen(['sqlplus', '-S', connectString], stdin=PIPE, stdout=PIPE, stderr=PIPE)
   session.stdin.write(sqlCommand)
   return session.communicate()

session = Popen(['sqlplus','-S','hr/hr'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = session.communicate()

sqlCommand = "insert into food(title, recipe, image) values ('bla','bla','bla');"
queryResult, errorMessage = runSqlQuery(sqlCommand, connectString)
print queryResult

它给了我以下错误:

C:\Python27\python.exe C:/Users/Umer/PycharmProjects/DATACRAWLER/main.py

Traceback (most recent call last):

  File "C:/Users/Umer/PycharmProjects/DATACRAWLER/main.py", line 38, in <module>

session = subprocess.Popen(['sqlplus','-S','hr/hr'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

  File "C:\Python27\lib\subprocess.py", line 710, in __init__
    errread, errwrite)

  File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
    startupinfo)

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

推荐答案

请考虑为命令执行使用绝对路径.
某些二进制文件不在PATH中,具体取决于您的用户,系统和软件安装.

Consider using an absolute path for your command-execution.
Some binaries are not located in PATH depending on your user, system and software installation.

要找出sqlplus的位置,请在cmd.exe中运行以下命令:where sqlplus,这应该为您提供绝对路径.

To find out where sqlplus resides, run the following in cmd.exe: where sqlplus and that should give you the absolute path.

然后只需:

Popen(['C:/path/sqlplus.exe', '-S', ...])

还要找出您的PATH环境变量中的实际内容,您可以执行以下操作:

Also to find out what's actually in your PATH environment variable, you could do the following:

print(os.environ['PATH'])

这篇关于子进程给出一个错误. “系统找不到指定的文件".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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