can not get output of shell script's echo to a Java variable -
i calling shell script java, in shell script running queries , getting running times,(e.g. when save echo time's result in output file, e.g. 28sec 27sec 34sec in 1 column) can not output of echo time java,when running program getting weird decimal numbers. code getting output shell script this:
import java.util.*; import java.io.*; public class test { public static void main(string[] args) { treemap <string, long> mymap = new treemap <string, long>(); string output = ""; string line = ""; mymap.put("key", value); mymap.put("key", value); list<string> cmdlist = new arraylist<string>(); cmdlist.add("/path/to/the/test/file/test.sh"); for(map.entry entry : mymap.entryset()) { cmdlist.add(entry.getkey().tostring()); cmdlist.add(entry.getvalue().tostring()); } try { process process = runtime.getruntime().exec(cmdlist.toarray(new string[cmdlist.size()])); //get input stream of process bufferedreader in = new bufferedreader(new inputstreamreader(process.getinputstream())); while ((line = in.readline()) != null) { output += line; } } catch(ioexception e){ system.out.println("caught ioexception: " + e.getmessage()); } system.out.println(output); } }
my shell script looks this:
i=0 args=("$@") while [ $i -lt $# ] start=`date +%s` operation here end=`date +%s` echo $end - $start | bc done
weird output java:
f 37734107.00 56586554400.73 53758257134.8700 55909065222.827692 25.522006 38273.129735 0.049985 1478493n 991417.00 1487504710.38 1413082168.0541 1469649223.194375 25.516472 38284.467761 0.050093 38854n o
what might doing wrong in code?
Comments
Post a Comment