Trying to run multiple python scripts in Java
<p>I have a python script called generate_graphs.py that generates graphs with python libraries. The graphs are trends we show to customers with our internal data. </p>

<p>I'm trying to run the script from Java, but I don't see any evidence of it running. There is no evidence of logs showing it ran, but I'm not sure if this is the script itself not running, or if its the implementation of the exec method.</p>

<p>The script inserts data into a database as part of its process, and nothing is inserted. However, when running the script command from command line separately, the script runs perfectly fine.</p>

<p>Here's the execute command implementation used from mkyong.com:</p>

<pre><code>private String executeCommand(String command) {

    StringBuffer output = new StringBuffer();

    Process p;
    try {
        p = Runtime.getRuntime().exec(command);
        p.waitFor();
        BufferedReader reader =
                new BufferedReader(new InputStreamReader(p.getInputStream()));

        String line = "";
        while ((line = reader.readLine())!= null) {
            output.append(line + "\n");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return output.toString();

}
</code></pre>

<p>Here's the method that is called about 40 times in total, roughly once per 3 seconds:</p>

<pre><code>/**
 * Runs a command to execute the generate_graph python script
 *
 * @param server_id
 */
public void generateGraph(List&lt;String&gt; list_name, String server_id, String email_addr, String report_str) {

    String generate_graph_cmd = "python2.7 generate_graphs.py --l '%s' --server_name '%s' --email_addr '%s'  --report_string '%s' --debug";
    //We want to remove the lm_ part from the server name
    String server_name = server_id.split("_")[1].replace("\'", "");
    String list_name_str = "";

    for (String name : list_name){
        list_name_str += name + ",";
    }
    //We want to remove the trailing comma left by the above loop
    if (list_name_str.length() &gt; 1){
        list_name_str = list_name_str.substring(0, list_name_str.length() - 1);
    }


    generate_graph_cmd = String.format(generate_graph_cmd, list_name_str, server_name, email_addr, report_str);

try {

    System.out.println("[Py Output] " + executeCommand(generate_graph_cmd));

    } catch (Exception e) {
        e.printStackTrace();
    }
    log.debug("Generating graph with the following parameters:\nserver_id: " + server_id + "\nlist_id: " + list_name.toString());
}
</code></pre>

<p>I only see the <code>log.debug</code> portion of the output in the logs. Am I calling it too quickly/incorrectly? Any help would be appreciated, thanks!</p>

<p>I ended up using <a href="https://commons.apache.org/proper/commons-exec/download_exec.cgi" rel="nofollow">Apache Common's Exec</a> to solve my issue. </p>

java python logging command-line command