Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling Python script from JAVA MySQLdb imports
    primarykey
    data
    text
    <p>I am calling a Python script from my Java code. This is the code : </p> <pre> import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class JavaRunCommand { public static void main(String args[]) throws IOException { // set up the command and parameter String pythonScriptPath = "my-path"; String[] cmd = new String[2]; cmd[0] = "python2.6"; cmd[1] = pythonScriptPath; // create runtime to execute external command Runtime rt = Runtime.getRuntime(); Process pr = rt.exec(cmd); // retrieve output from python script BufferedReader bfr = new BufferedReader(new InputStreamReader( pr.getInputStream())); String line = ""; while ((line = bfr.readLine()) != null) { // display each output line form python script System.out.println(line); } } } </pre> <p><b> python.py </b> which works</p> <pre> import os from stat import * c = 5 print c </pre> <p><b> python.py </b> which does not works</p> <pre> import MySQLdb import os from stat import * c = 5 print c # some database code down </pre> <p>So, I am at a critical stage where I have a deadline for my startup and I have to show my MVP project to the client and I was thinking of calling Python script like this. It works when I am printing anything without dB connection and MySQLdb library. But when I include them, it does not run the python script. Whats wrong here. Isnt it suppose to run the process handling all the inputs. I have MySQLdb installed and the script runs without the java code. </p> <p>I know this is not the best way to solve the issue. But to show something to the client I need this thing working. Any suggestions ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload