package a1;
import java.io.*;
/************************************************************
H:\DATI\Studi\JAVA\a1>java -cp classes a1.Runtime_2
main err.: Numero paramentri non valido
H:\DATI\Studi\JAVA\a1>java -cp classes a1.Runtime_2 xdummy
Runtime_2 r2 = new Runtime_2( xdummy )
IOException: CreateProcess: xdummy error=2
H:\DATI\Studi\JAVA\a1>java -cp classes a1.Runtime_2 sol
Runtime_2 r2 = new Runtime_2( sol )
***********************************************************/
public class Runtime_2 {
public Runtime_2( String str_cmd )
{
try { Runtime.getRuntime().exec( str_cmd ); }
catch (RuntimeException e ) { System.out.println( "RuntimeException: " + e.getMessage()); }
catch (IOException e ) { System.out.println( "IOException: " + e.getMessage()); }
catch (Exception e ) { System.out.println( "Exception: " + e.getMessage()); }
}
public static void main(String[] args)
{
try
{
// test numero di parametri
if( args.length < 1 )
{ throw new Exception( "Numero paramentri non valido" ); }
System.out.println( " Runtime_2 r2 = new Runtime_2( " + args[0] + " ) " );
Runtime_2 r2 = new Runtime_2( args[0] );
}
catch ( Exception e ) { System.out.println( "main err.: " + e.getMessage()); }
}
}
|