2016-05-25 6 views
0

コマンドラインに「python」と入力するだけで、吐き出されたテキストを取得できないはずですか?Pythonスクリプトのstd出力を文字列としてコマンドラインに格納することはできません

try { 
     Process proc = Runtime.getRuntime().exec("python"); 
     BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream())); 
     String result = null; 
     while ((result = reader.readLine()) != null) { 
      PrintWriter out = resp.getWriter(); 
      out.println("<div>" + result + "</div>"); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

望ましい結果は次のようになります。python C:\Users\Me\HelloWorld.pyを実行

Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AM 
D64)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> 
+0

を? –

+0

何もありません。私もエラーはありません。 PythonコマンドをRuntimeから解釈したくないようです。 – santafebound

+0

それは 'while'ループに詰まってしまったのでしょうか、それとも、すべて終了したのでしょうか? –

答えて

0

は、スクリプトを実行し、標準出力を収集:*代わりに*だから、何をするのか

try { 
     Process proc = Runtime.getRuntime().exec("python C:\Users\Me\HelloWorld.py"); 
     BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream())); 
     String result = null; 
     while ((result = reader.readLine()) != null) { 
      PrintWriter out = resp.getWriter(); 
      out.println("<div>" + result + "</div>"); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
関連する問題