Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class procesos5 {
- public static void main(String[] args) {
- Runtime r = Runtime.getRuntime();
- Process p = null;
- try{
- p= r.exec ("java Escritura");
- OutputStream os = p.getOutputStream();
- os.write (args[0].getBytes());
- os.flush();
- InputStream is = p.getInputStream();
- BufferedReader br= new BufferedReader (new InputStreamReader( is) );
- String linea;
- while((linea = br.readLine())!=null){
- System.out.println(linea);
- }//END WHILE
- br.close();
- }catch (Exception e) {
- System.out.println ("Debes pasar un argumento");
- System.exit(-1);
- }
- try{
- int exitVal = p.waitFor();
- System.out.println("Calor de salida:"+ exitVal);
- }catch(InterruptedException e){
- e.printStackTrace();
- }
- }
- }
- public class Escritura {
- public static void main(String[] args) throws IOException {
- System.out.println("Segundo programa");
- String nombre = "argumento";
- try {
- PrintWriter pw = new PrintWriter(new File("fichero.txt"));
- pw.print("nuevo fichero");
- pw.close();
- System.out.println("Fichero creado correctamente");
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Escritura.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Add Comment
Please, Sign In to add comment