F
FET
Hi all,
I am using the following snippet of code in a program of mine:
final String[] saCommandArray =
{
"/bin/sh" ,
"scripts/RESTORE_MY_DB.sh" ,
"192.12.52.21" ,
"5432" ,
"mydb_admin" ,
"my_db" ,
"mydbpass" ,
"MY_BACKUP_FILE.SQL"
};
Process proc = Runtime.getRuntime().exec ( saCommandArray ) ;
//////////////////FROM HERE//////////////////
BufferedInputStream bis = new BufferedInputStream (
proc.getInputStream () ) ;
BufferedOutputStream fos = new BufferedOutputStream ( new
FileOutputStream ( "/tmp/out" ) );
int iRead = 0 ;
while ( (iRead = bis.read () ) != -1 )
{
fos.write ( iRead ) ;
}
fos.close () ;
bis.close () ;
/////////////////TILL HERE////////////////
final int iWait = proc.waitFor() ;
final int iRetVal = proc.exitValue() ;
if ( 0 != iRetVal )
{
throw new Exception ( "Error, script returned " +
Integer.toString ( iRetVal ) ) ;
}
If I comment the block of code between "FROM HERE" to "TILL HERE",
then the waitFor () call just hangs. But with that block of code in
place, then command executes successfully and comes out of the waitFor
because the process is over by the time the WHILE loop finishes
executing.
What is the reason for this strange behaviour ? I am using Linux, and
the shell script that is being executed produces a lot of output
statements (basically its a 'psql' call).
Please help.
Thanks in advance.
Best regards.
I am using the following snippet of code in a program of mine:
final String[] saCommandArray =
{
"/bin/sh" ,
"scripts/RESTORE_MY_DB.sh" ,
"192.12.52.21" ,
"5432" ,
"mydb_admin" ,
"my_db" ,
"mydbpass" ,
"MY_BACKUP_FILE.SQL"
};
Process proc = Runtime.getRuntime().exec ( saCommandArray ) ;
//////////////////FROM HERE//////////////////
BufferedInputStream bis = new BufferedInputStream (
proc.getInputStream () ) ;
BufferedOutputStream fos = new BufferedOutputStream ( new
FileOutputStream ( "/tmp/out" ) );
int iRead = 0 ;
while ( (iRead = bis.read () ) != -1 )
{
fos.write ( iRead ) ;
}
fos.close () ;
bis.close () ;
/////////////////TILL HERE////////////////
final int iWait = proc.waitFor() ;
final int iRetVal = proc.exitValue() ;
if ( 0 != iRetVal )
{
throw new Exception ( "Error, script returned " +
Integer.toString ( iRetVal ) ) ;
}
If I comment the block of code between "FROM HERE" to "TILL HERE",
then the waitFor () call just hangs. But with that block of code in
place, then command executes successfully and comes out of the waitFor
because the process is over by the time the WHILE loop finishes
executing.
What is the reason for this strange behaviour ? I am using Linux, and
the shell script that is being executed produces a lot of output
statements (basically its a 'psql' call).
Please help.
Thanks in advance.
Best regards.