0

Hi i'm trying to make a backup using rman from java, im trying using a Runtime from java, im able to open the cmd, access rman but after that any other query i try to submit is executed. im able to access rman from cmd window and sqlplus window i alredy tried using ; and without it here's the code, please help me:

public void execute(JobExecutionContext context) throws JobExecutionException {
         command[0] = "cmd";
         command[1] = "/c";
         command[2] = "rman target / catalog rman/rman@xe;";
         command[3] = "backup as backupset database plus archivelog;";
         command[4] = "exit;";
         command[5] = "sqlplus.exe;";
         try {  
         Process p = Runtime.getRuntime().exec(command);

         BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
         String line = reader.readLine();
         while (line != null) {
             System.out.println(line);
             line = reader.readLine();
         }

And this is the output:

Recovery Manager: Release 11.2.0.2.0 - Production on Lun Nov 11 22:11:12 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: XE (DBID=2711152663)
connected to recovery catalog database
MaynorSong
  • 630
  • 7
  • 15

2 Answers2

0

See Problem with the output of a cmd command in java ...specifically if you have multiple commands that you are wanting cmd to execute you have to use the & symbol to join them together.

Community
  • 1
  • 1
JohnKlehm
  • 2,368
  • 15
  • 9
0

If you want to run commands as if you were in an "interactive" session, you will need to spawn "cmd.exe", then use p.getOutputStream() to "write" commands to execute.

Something like:

ProcessBuilder pb = new ProcessBuilder("cmd.exe");
pb.redirectErrorStream(true);
Process p = pb.start();
PrintWriter writer = new PrintWriter(p.getOutputStream());
writer.println("rman target / catalog rman/rman@xe;");
writer.println("backup as backupset database plus archivelog;");
writer.println("exit;");
writer.println("sqlplus.exe;");

Note: if you don't read the p.getInputStream() between commands you will likely block.

brettw
  • 10,664
  • 2
  • 42
  • 59