Shell command not executing in Java -
this question has answer here:
normally when this:
printf 'select x y \ngo\n' | isql -uxx -pxxxxxx -dxxxxx -w 65535 -s ','
on command line executes fine.
even below java code. works fine
public class test { public static void main(string[] args) { string db="|isql -uxx -pxxxxxx -dxxxxx -w 65535 -s ','"; string qpfx="printf \'"; string qsfx=" \ngo\n\'"; if(args[0]!=null) try { string cmd=qpfx+args[0]+qsfx+db; system.out.println("argument query is:"+args[0]); system.out.println("command is:"+cmd); process p = runtime.getruntime().exec(new string[]{"sh","-c",cmd}); p.waitfor(); bufferedreader reader = new bufferedreader(new inputstreamreader(p.getinputstream())); string line=reader.readline(); while (line != null) { system.out.println(line); line = reader.readline(); } } catch(ioexception e1) {} catch(interruptedexception e2) {} } }
i run above java code below:
java test "select x y"
probelm comes when give select query "select * y" instead of column names. when wanted execute below:
java test "select * y"
the above jav code hangs.can body tell me reason why?
below output hanging:
> java test "select * y" argument query is:select * y command is:printf 'select * y go '|isql -uxx -pxxxxx -dxxxxxx -w 65535 -s ','
i tried:
java test "select \* y"
but not execute.
after severe debugging found line hanging p.waitfor();
.
i had read this complete article , found solution. have shifted p.waitfor();
after while loop in code , worked.
Comments
Post a Comment