Skip to main content
added 53 characters in body
Source Link
Shahab
  • 2.1k
  • 7
  • 25
  • 28

I'm trying to run a python script during the execution of my java code, because it will depend on the output received from the python script. So far I've tried using jythonc, unfortunately to no success, and now im trying to use the java Runtime and java Process to execute the python script.

Now I've run into a problem when trying to call the python script. I feel as though it doesn't even call the script because it takes less than a couple seconds to get to the next page....

Could the problem be how I am calling the python script?? I am trying to run this through a web application...

Here is some of my code:

    String run = "cmd /c python duplicatetestingoriginal.py" ;
    
    boolean isCreated = fwr.writeFile(BugFile, GD, 500, true, 5, "LET");
        
    if(isCreated){
        try{
            r = Runtime.getRuntime();
            p = r.exec(run);
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        
    String line = "";
    while ((line = stdInput.readLine()) != null) {
                System.out.println(line);
    }
    while ((line = stdError.readLine()) != null) {
               errorW.write(line);
    }
                    
            int exitVal = p.waitFor();
            arrayList = fwr.readResults();
        }catch(Exception e){
            
        }
    }
    else{
        // troubleshoot....
        
    }

I'm trying to run a python script during the execution of my java code, because it will depend on the output received from the python script. So far I've tried using jythonc, unfortunately to no success, and now im trying to use the java Runtime and java Process to execute the python script.

Now I've run into a problem when trying to call the python script. I feel as though it doesn't even call the script because it takes less than a couple seconds to get to the next page....

Could the problem be how I am calling the python script??

Here is some of my code:

    String run = "cmd /c python duplicatetestingoriginal.py" ;
    
    boolean isCreated = fwr.writeFile(BugFile, GD, 500, true, 5, "LET");
        
    if(isCreated){
        try{
            r = Runtime.getRuntime();
            p = r.exec(run);
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        
    String line = "";
    while ((line = stdInput.readLine()) != null) {
                System.out.println(line);
    }
    while ((line = stdError.readLine()) != null) {
               errorW.write(line);
    }
                    
            int exitVal = p.waitFor();
            arrayList = fwr.readResults();
        }catch(Exception e){
            
        }
    }
    else{
        // troubleshoot....
        
    }

I'm trying to run a python script during the execution of my java code, because it will depend on the output received from the python script. So far I've tried using jythonc, unfortunately to no success, and now im trying to use the java Runtime and java Process to execute the python script.

Now I've run into a problem when trying to call the python script. I feel as though it doesn't even call the script because it takes less than a couple seconds to get to the next page....

Could the problem be how I am calling the python script?? I am trying to run this through a web application...

Here is some of my code:

    String run = "cmd /c python duplicatetestingoriginal.py" ;
    
    boolean isCreated = fwr.writeFile(BugFile, GD, 500, true, 5, "LET");
        
    if(isCreated){
        try{
            r = Runtime.getRuntime();
            p = r.exec(run);
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        
    String line = "";
    while ((line = stdInput.readLine()) != null) {
                System.out.println(line);
    }
    while ((line = stdError.readLine()) != null) {
               errorW.write(line);
    }
                    
            int exitVal = p.waitFor();
            arrayList = fwr.readResults();
        }catch(Exception e){
            
        }
    }
    else{
        // troubleshoot....
        
    }
Source Link
Shahab
  • 2.1k
  • 7
  • 25
  • 28

Running Python scripts in Java

I'm trying to run a python script during the execution of my java code, because it will depend on the output received from the python script. So far I've tried using jythonc, unfortunately to no success, and now im trying to use the java Runtime and java Process to execute the python script.

Now I've run into a problem when trying to call the python script. I feel as though it doesn't even call the script because it takes less than a couple seconds to get to the next page....

Could the problem be how I am calling the python script??

Here is some of my code:

    String run = "cmd /c python duplicatetestingoriginal.py" ;
    
    boolean isCreated = fwr.writeFile(BugFile, GD, 500, true, 5, "LET");
        
    if(isCreated){
        try{
            r = Runtime.getRuntime();
            p = r.exec(run);
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        
    String line = "";
    while ((line = stdInput.readLine()) != null) {
                System.out.println(line);
    }
    while ((line = stdError.readLine()) != null) {
               errorW.write(line);
    }
                    
            int exitVal = p.waitFor();
            arrayList = fwr.readResults();
        }catch(Exception e){
            
        }
    }
    else{
        // troubleshoot....
        
    }