Home > Back-end >  For a minute ~ ~ want to consulting Java calls pythone script
For a minute ~ ~ want to consulting Java calls pythone script

Time:10-26

 package test; 

Import the Java. IO. BufferedReader;
Import the Java. IO. InputStreamReader;

Public class Test {
Public static void main (String [] args) {
The arguments=new String String [] [] {" python ", "F: \ \ workspace \ \ python \ \ hello py"};
Try {
System. The out. Println (" start ");
Process Process=Runtime. GetRuntime (). The exec (the arguments);
BufferedReader in=new BufferedReader (new InputStreamReader (process. The getInputStream (), "GBK"));
The String line=null;
While ((line=in readLine ())!=null) {
System. The out. Println (line);
}
in.close();
Process. The destroy ();
Int re=process. WaitFor ();
System. The out. Println (re + "--");
System. The out. Println (" end ");
} the catch (Exception e) {
System.out.println(e.getMessage());
}
}
}



I use this method call python scripts, the console output information is as follows:

 D: \ JDK \ bin \ Java - Didea. The launcher. The port=7533 "- Didea. The launcher. Bin. Path=D: \ IDE2016 \ \ IDE IntelliJ IDEA 2016.1.2 \ bin" - Dfile. Encoding=utf-8 - classpath "D: \ JDK \ jre \ lib \ charsets jar; D: \ JDK \ jre \ lib \ deploy the jar. D: \ JDK \ jre \ lib \ ext \ access - bridge - 64. The jar. D: \ JDK \ jre \ lib \ ext \ cldrdata jar; D: \ JDK \ jre \ lib \ ext \ DNSNS jar; D: \ JDK \ jre \ lib \ ext \ jaccess jar; D: \ JDK \ jre \ lib \ ext \ JFXRT jar; D: \ JDK \ jre \ lib \ ext \ localedata jar; D: \ JDK \ jre \ lib \ ext \ nashorn jar; D: \ JDK \ jre \ lib \ ext \ sunec jar; D: \ JDK \ jre \ lib \ ext \ sunjce_provider jar; D: \ JDK \ jre \ lib \ ext \ sunmscapi jar; D: \ JDK \ jre \ lib \ ext \ sunpkcs11 jar; D: \ JDK \ jre \ lib \ ext \ zipfs jar; D: \ JDK \ jre \ lib \ javaws jar; D: \ JDK \ jre \ lib \ jce jar; D: \ JDK \ jre \ lib \ JFR jar; D: \ JDK \ jre \ lib \ JFXSWT jar; D: \ JDK \ jre \ lib \ jsse jar; D: \ JDK \ jre \ lib \ management - agent jar; D: \ JDK \ jre \ lib \ plugin jar; D: \ JDK \ jre \ lib \ resources jar; D: \ JDK \ jre \ lib \ rt jar; F: \ workspace \ workspaceForIDE \ out \ production \ workspaceForIDE; D: \ IDE2016 \ \ IDE IntelliJ IDEA 2016.1.2 \ lib \ idea_rt jar ". Com. IntelliJ. Rt execution. Application. AppMain test. The test 
Start
9009 -
End

The Process finished with exit code 0


Tried many ways can't, don't know because local python environment or no causes, more worry, request the great god help me ~ ~ ~ ~ ~ ~

CodePudding user response:

I tried your code, can the normal calls!
Estimate is not local python environment!

CodePudding user response:

reference 1st floor paullbm response:
I tried your code, can the normal calls!
Estimate is not local python environment!


My local installation anaconda, common use spyder running python scripts, I learn Java, how can I set the python environment, is to set up environment variables such as?

CodePudding user response:

refer to the second floor night god on write a diary to reply:
Quote: refer to 1st floor paullbm response:

I tried your code, can the normal calls!
Estimate is not local python environment!


My local installation anaconda, common use spyder running python scripts, I learn Java, how can I set the python environment, is to set up environment variables such as?


Installation anaconda containing the python, you put the anaconda python configure an environment variable, then add to the path to try!
For example:
The environment variable called: PYTHONPATH
Environment variable value is: .; E: \ Python \ Python38-32 \; E: \ Python38-32 \ \ Python Scripts (according to the two paths modified into your)
  • Related