dcsimg
linux system calls
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, January 16, 2003 02:59 PM

is there a way to make a linux system call through a JavaBean file? I am trying to run a perl script from a JavaBean and it seems that calling a system call would be the easiest way, but I can't find any documentation on this.
thanks.

Re: linux system calls

Posted By:   James_Bayer  
Posted On:   Thursday, January 16, 2003 03:13 PM


Process p = Runtime.getRuntime().exec( "ping localhost") ;

//you may want to monitor the output...this will allow you to do that without blocking
Thread thread = new Thread()
{
public void run()
{
try
{
BufferedReader reader = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
long lTimeLastSuccess =System.currentTimeMillis();
long lTimeElapsed = 0;
String strLine = reader.readLine();

//if it hasn't been three minutes yet
while( lTimeElapsed < 300000 )
{
if( strLine == null )
{
//check to see if the process is still alive
try
{
int iExitCode = p.exitValue();
System.out.println( p + " has exited with code: " + iExitCode );
return;
}
catch( Throwable t )
{}
Thread.sleep( 1000 );
lTimeElapsed = System.currentTimeMillis() - TimeLastSuccess;
}
else
{
System.out.println( strLine );
lTimeLastSuccess = System.currentTimeMillis();
lTimeElapsed = 0;
}
strLine = reader.readLine();
}
}
catch( Throwable t )
{
System.err.println( "Monitoring Thread Error: " + t );
}
}
);
thread.start();

About | Sitemap | Contact