0

I am passing string values to a python script from java. In my python script i am using the parameters but i could not able to read the 2 values.Plz help

Java Code:

String filePath = "E:\\Project_ivin\\test.py";  
ProcessBuilder pb = new ProcessBuilder().command("python", "-u", filePath, ""+issueId+""+comments);        
Process p = pb.start(); 

python script:

sys.argv[1] # issueid

sys.argv[2]  # comments
Eritrean
  • 15,851
  • 3
  • 22
  • 28

1 Answers1

0

Seems comma is missing, else use 3rd argument.

Java:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
  public static void main(String[] args) throws IOException, InterruptedException {
    String[] list = { "python", "-u", "in.py", "issueId", "comments" };
    ProcessBuilder pb = new ProcessBuilder().command(list);
    Process p = pb.start();
    System.out.println("" + pb.command());
    p.waitFor();
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    StringBuilder sb = new StringBuilder();
    while ((line = br.readLine()) != null)
      sb.append(line);
    System.out.println(sb.toString());
  }
}

Python:

# print(sys.argv[0]) // this will be file name

print(sys.argv[1])
print(sys.argv[2])
xdeepakv
  • 7,835
  • 2
  • 22
  • 32