Hi All,
Please check the below program while is not executing, when the
unix command's having \&\& is used.
The following command copies the src folder to dest folder with
out data loss ...
<CODE>
import java.io.*;
import java.util.*;
public class Sample
{
public static void main(
String[] args)
{
try {
String ExCmd="ssh
oradev@dev.excl.com cd /u01/11510/devdb/9.2.0/slax \\&\\&
/bin/tar cf - . | ssh
oratest@test.excl.com cd
/d01/AppsTest/testappl2 \\&\\& /bin/tar -xf - > test.log";
System.out.println("Command to execute :
"+ExCmd);
Process SshProc =
(Runtime.getRuntime()).exec(ExCmd);
// any error message?
StreamReader errorStream = new
StreamReader(SshProc.getErrorStream(), "DEBUG");
// any output?
StreamReader outputStream = new
StreamReader(SshProc.getInputStream(), "OUTPUT");
// kick them off
errorStream.start();
outputStream.start();
int pp =SshProc.waitFor();
System.out.println("command execution value:
"+pp);
}catch(Exception e) {
e.printStackTrace();
}
}
}
class StreamReader extends
Thread {
InputStream is;
String type;
StreamReader(InputStream is, String type)
{
this.is = is;
this.type = type;
}
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null) {
System.out.println(type + ">" + line);
}
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
</CODE>
When this is executed iam getting process value as "0".
But nothing is copying to target ..
So to resolve this i have created a script .. and passed
arguments to that script and chaged command as follows :
<CODE>
String ExCmd = "sh /home/juser/movedir.sh
oradev@dev.excl.com /u01/11510/devdb/9.2.0/slax /bin/tar
oratest@test.excl.com /d01/AppsTest/testappl2 /bin/tar /home/juser/test";
</CODE>
Then it is executing fine. But in my scenario iam restricted to
use scripts.
So please can any body have a solution for this.
Thanks, SN