By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,117 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,117 IT Pros & Developers. It's quick & easy.

run python file from java class by eclipse IDE

P: 21
This program (below), I am able to run from command prompt but when i am using eclipse that is not returning any text.

May this is not running python file

java file and python file is present in bin folder when i am using command prompt

when i am using eclipse java and python both file is present in default package .

what i do to run python file from java class by eclipse IDE ?
Expand|Select|Wrap|Line Numbers
  1. public class TestE 
  2. {
  3.     static String returnText(String s7) 
  4.     {    StringBuilder result=null;    
  5.     try{
  6.             final String command = "python sir_desc.py "+s7;
  7.             final Process sirDesc = Runtime.getRuntime().exec(command);
  8.  
  9.             final java.io.InputStream inStreamBase = sirDesc.getInputStream();
  10.  
  11.             final java.io.InputStreamReader inStreamISR = new java.io.InputStreamReader(inStreamBase);
  12.  
  13.             final java.io.BufferedReader inStream = new java.io.BufferedReader(inStreamISR);
  14.  
  15.             String inLine;
  16.  
  17.             result = new StringBuilder();
  18.  
  19.             while (null != (inLine = inStream.readLine()))
  20.  
  21.             result.append(inLine);
  22.  
  23.             }
  24.             catch(Exception e){}
  25.         return result.toString();
  26.     }
  27.  
  28.  
  29.  public static void main(String args[])
  30.  {
  31.      System.out.println("start  :  "+returnText("https://en.wikipedia.org/wiki/Varanasi"));
  32.  }
  33. }
Attached Files
File Type: txt sir_desc.py.txt (5.7 KB, 128 views)
Nov 18 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.