how run a command on Oracle VM

119 views Asked by At

We have oracle virtual machine installed in our solaris machine. (we need waptpro tool which can be installed only on windows). So, we have this tool installed on oracle virtual machine.

Now I have a java code on my solaris machine. I need to execute waptpro tool from solaris machine. If there any command where i can run the command on oracle virtual machine from solaris I can integrate this in my javacode

So, please let me know if anyone know how to execute a command on oracle virtual machine from solaris.

1

There are 1 answers

1
Thorbjørn Ravn Andersen On

This is something that is easy in the simplest case but require quite a bit of elbow grease to get right for all cases.

From http://www.rgagnon.com/javadetails/java-0014.html for Java 1.5 and later (adapt the command as needed):

import java.io.*;
import java.util.*;

public class CmdProcessBuilder {
  public static void main(String args[])
     throws InterruptedException,IOException
  {
    List<String> command = new ArrayList<String>();
    command.add(System.getenv("windir") +"\\system32\\"+"tree.com");
    command.add("/A");

    ProcessBuilder builder = new ProcessBuilder(command);
    Map<String, String> environ = builder.environment();
    builder.directory(new File(System.getenv("temp")));

    System.out.println("Directory : " + System.getenv("temp") );
    final Process process = builder.start();
    InputStream is = process.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line;
    while ((line = br.readLine()) != null) {
      System.out.println(line);
    }
    System.out.println("Program terminated!");
  }
}