jdk/src/windows/classes/sun/tools/attach/WindowsVirtualMachine.java
InputStream execute(String cmd, Object ... args)
throws AgentLoadException, IOException
{
{- -------------------------------------------
(1) (assert)
---------------------------------------- -}
assert args.length <= 3; // includes null
{- -------------------------------------------
(1)
---------------------------------------- -}
// create a pipe using a random name
int r = (new Random()).nextInt();
String pipename = "\\\\.\\pipe\\javatool" + r;
long hPipe = createPipe(pipename);
{- -------------------------------------------
(1)
---------------------------------------- -}
// check if we are detached - in theory it's possible that detach is invoked
// after this check but before we enqueue the command.
if (hProcess == -1) {
closePipe(hPipe);
throw new IOException("Detached from target VM");
}
try {
// enqueue the command to the process
enqueue(hProcess, stub, cmd, pipename, args);
// wait for command to complete - process will connect with the
// completion status
connectPipe(hPipe);
// create an input stream for the pipe
PipedInputStream is = new PipedInputStream(hPipe);
// read completion status
int status = readInt(is);
if (status != 0) {
// special case the load command so that the right exception is thrown
if (cmd.equals("load")) {
throw new AgentLoadException("Failed to load agent library");
} else {
throw new IOException("Command failed in target VM");
}
}
// return the input stream
return is;
} catch (IOException ioe) {
closePipe(hPipe);
throw ioe;
}
}
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.