Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subprocess gives an error. "The system cannot find the file specified"

This is my code:

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

And it gives me the following error:

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
like image 844
Umer Javed Avatar asked Jan 21 '26 05:01

Umer Javed


1 Answers

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

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

Then simply do:

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

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

print(os.environ['PATH'])
like image 66
Torxed Avatar answered Jan 23 '26 01:01

Torxed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!