Running bash script from java

my problem is simple, when I try to run a .sh script from Java, the script does not execute. If I change my script to a simple linux command such as ls -all, it works fine, so I assume that I use a bad command in my script that stops execution. Please, help.

David

Java Code:

    String cmd = "bash /home/david/burza/getter.sh";

    try {
        Process proc = Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", cmd});
        BufferedReader read = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        try {
            proc.waitFor();
        } catch (InterruptedException e) {
            System.out.println(e.getMessage());
        }
        while (read.ready()) {
            System.out.println(read.readLine());
        }
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }

Bash script:

#! /bin/bash 

wget -O data1.html http://www.rmsystem.cz/kurzy-online/akcie/easyclick;
touch ext_data.txt; 

grep 'table class="tbl1"' ./data1.html | tr '<td>' ' ' | tr '-' 'A' | grep -o -w '[0-9, ]*' | sed 's/  *//g' | sed '/^$/d' | tr ',' '.' > ext_data.txt;

lines=`wc -l ext_data.txt | grep -o '[0-9]*'`;

( echo $lines; cat ext_data.txt ) > ext_data.txt.new && mv ext_data.txt.new ext_data.txt;
+5
source share
1 answer

Start by removing "bash" from the beginning of the command.

Secondly, I'm not sure what the shell will do #! interpretation when not used interactively. I would like to go directly to / bin / bash to call Runtime.exec ().

, , stdout, . stderr, , . , (proc.waitFor()), . , , , , .

4 : http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1

+2

All Articles