Normally when i do this:
printf 'select x from Y \ngo\n' | isql -Uxx -Pxxxxxx -Dxxxxx -w 65535 -s ','
on the command line it executes fine.
even with the below java code. it 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 will run this above java code like below:
java test "select x from Y"
Probelm comes when i give the select query as "select * from Y" instead of column names. That is when i wanted to execute like below:
java test "select * from Y"
The above jav code hangs.Can any body tell me the reason why?
below is the output where its hanging:
> java test "select * from Y"
argument query is:select * from Y
Command is:printf 'select * from Y
go
'|isql -Uxx -Pxxxxx -Dxxxxxx -w 65535 -s ','
I also tried:
java test "select \* from Y"
But it does not execute.
'in your Strings? Or are there necessary?String qsfx=" ;go;\'";make a difference?System.out.println("Command is:"+cmd);print in output?printf 'select * from Y \ngo\n' | isql -Uxx -Pxxxxxx -Dxxxxx -w 65535 -s ','from the command line?