1
package org.jvnet.hudson.remcom;
3
import org.apache.commons.io.FileUtils;
4
import org.apache.commons.io.IOUtils;
5
import org.jinterop.dcom.common.IJIAuthInfo;
6
import org.jinterop.dcom.common.JIDefaultAuthInfoImpl;
7
import org.jinterop.dcom.common.JIException;
10
import java.io.IOException;
11
import java.io.OutputStream;
12
import java.util.logging.ConsoleHandler;
13
import java.util.logging.Level;
14
import java.util.logging.Logger;
20
private static IJIAuthInfo createAuth() throws IOException {
21
String pwd = FileUtils.readFileToString(new File("/home/kohsuke/.cubit")).trim();
22
return new JIDefaultAuthInfoImpl("cloud", "kohsuke", pwd);
23
// return new JIDefaultAuthInfoImpl("", "kohsuke", "kohsuke");
26
public static void main(String[] args) throws Exception {
27
Logger.getLogger("org.jinterop").setLevel(Level.WARNING);
28
Logger l = Logger.getLogger("org.jvnet.hudson");
29
l.setLevel(Level.ALL);
30
ConsoleHandler ch = new ConsoleHandler();
31
ch.setLevel(Level.ALL);
34
// String host = "10.1.6.71";
35
String host = "10.1.68.89";
38
// blockingTest(host);
40
// permissionTest(host);
43
private static void installJdk(String host) throws IOException, JIException, InterruptedException {
44
WindowsRemoteProcessLauncher wrp = new WindowsRemoteProcessLauncher(host, createAuth());
45
Process proc = wrp.launch("c:\\hudson\\jdk.exe /s \"/v/qn REBOOT=Suppress INSTALLDIR=c:\\hudson\\jdk /L c:\\hudson/jdk.exe.install.log\"", "c:\\");
46
proc.getOutputStream().close();
47
IOUtils.copy(proc.getInputStream(),System.out);
50
System.out.println("Exit code="+proc.waitFor());
53
private static void blockingTest(String host) throws IOException, JIException, InterruptedException {
54
WindowsRemoteProcessLauncher wrp = new WindowsRemoteProcessLauncher(host, createAuth());
55
Process proc = wrp.launch("c:\\cygwin\\bin\\cat", "c:\\");
56
IOUtils.copy(proc.getInputStream(),System.out);
59
System.out.println("Exit code="+proc.waitFor());
62
private static void permissionTest(String host) throws IOException, JIException, InterruptedException {
63
WindowsRemoteProcessLauncher wrp = new WindowsRemoteProcessLauncher(host, createAuth());
64
Process proc = wrp.launch("c:\\cygwin\\bin\\cat > iAmHere", "c:\\");
65
OutputStream o = proc.getOutputStream();
66
o.write("Hello world".getBytes());
68
IOUtils.copy(proc.getInputStream(),System.out);
69
IOUtils.copy(proc.getErrorStream(),System.out);
72
System.out.println("Exit code="+proc.waitFor());
75
proc = wrp.launch("dir", "c:\\");
77
o = proc.getOutputStream();
78
o.write("Hello world".getBytes());
80
IOUtils.copy(proc.getInputStream(),System.out);
81
IOUtils.copy(proc.getErrorStream(),System.out);
84
System.out.println("Exit code="+proc.waitFor());