无法在命令行中将python脚本的std输出存储为字符串

时间:2016-05-25 09:44:55

标签: java python runtime

我不能简单地键入" python"在我的命令行中并检索吐出的文本?

    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 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.
>>>

1 个答案:

答案 0 :(得分:0)

运行SET /p word=device FOR /f "delims=" %%a IN ('dir /a-d /b "Input_%date%.txt"') DO ( SET "fname=%%~na" SET "fname=!fname:%word%=!"' IF NOT "!fname!"=="" REN "%%~a" "!fname!%%~xa" 执行脚本并收集标准输出:

1015faf2da091b02    device
1115fbd4e0dd3b03    device