How to run interactive python script using apache common exec?

感情迁移 提交于 2019-12-24 02:25:24

问题


I am trying to run a python script using Apache Commons exec.I need to pass some values to python script as python script in an interactive one.How to do it?

My attempt was to set values in parent process's input stream.But it's not working for me.

My code so far:

String line = "python /home/abhijeet/test.py";

    CommandLine cmdLine = CommandLine.parse(line);

    byte buf[]="4".getBytes();

    InputStream io=new ByteArrayInputStream(buf);

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();

    PumpStreamHandler streamhandler=new PumpStreamHandler(System.out,System.err,io);



    DefaultExecutor executor = new DefaultExecutor();

    executor.setStreamHandler(streamhandler); 

    executor.execute(cmdLine, resultHandler);



    try
    {
        resultHandler.waitFor();
    }

    catch (InterruptedException e) 
    {
        System.out.println("yo errior");
        e.printStackTrace();
    }

来源:https://stackoverflow.com/questions/25680210/how-to-run-interactive-python-script-using-apache-common-exec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!