我的问题很简单,我试图从Java运行.sh脚本时,脚本没有执行。如果我将脚本更改为一个简单的Linux命令,例如ls -all,则可以完美地工作,因此我猜测在我的脚本中使用了错误的命令,导致停止执行。请帮忙。
David
Java代码:
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脚本:
#! /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;