|
|
@ -189,8 +189,9 @@ public class ProcessBuilderForWin32 { |
|
|
|
* @throws NullPointerException if the argument is null |
|
|
|
* @throws NullPointerException if the argument is null |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ProcessBuilderForWin32(List<String> command) { |
|
|
|
public ProcessBuilderForWin32(List<String> command) { |
|
|
|
if (command == null) |
|
|
|
if (command == null) { |
|
|
|
throw new NullPointerException(); |
|
|
|
throw new NullPointerException(); |
|
|
|
|
|
|
|
} |
|
|
|
this.command = command; |
|
|
|
this.command = command; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -207,8 +208,9 @@ public class ProcessBuilderForWin32 { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ProcessBuilderForWin32(String... command) { |
|
|
|
public ProcessBuilderForWin32(String... command) { |
|
|
|
this.command = new ArrayList<>(command.length); |
|
|
|
this.command = new ArrayList<>(command.length); |
|
|
|
for (String arg : command) |
|
|
|
for (String arg : command) { |
|
|
|
this.command.add(arg); |
|
|
|
this.command.add(arg); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -238,8 +240,9 @@ public class ProcessBuilderForWin32 { |
|
|
|
* @throws NullPointerException if the argument is null |
|
|
|
* @throws NullPointerException if the argument is null |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ProcessBuilderForWin32 command(List<String> command) { |
|
|
|
public ProcessBuilderForWin32 command(List<String> command) { |
|
|
|
if (command == null) |
|
|
|
if (command == null) { |
|
|
|
throw new NullPointerException(); |
|
|
|
throw new NullPointerException(); |
|
|
|
|
|
|
|
} |
|
|
|
this.command = command; |
|
|
|
this.command = command; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
@ -257,8 +260,9 @@ public class ProcessBuilderForWin32 { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ProcessBuilderForWin32 command(String... command) { |
|
|
|
public ProcessBuilderForWin32 command(String... command) { |
|
|
|
this.command = new ArrayList<>(command.length); |
|
|
|
this.command = new ArrayList<>(command.length); |
|
|
|
for (String arg : command) |
|
|
|
for (String arg : command) { |
|
|
|
this.command.add(arg); |
|
|
|
this.command.add(arg); |
|
|
|
|
|
|
|
} |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -344,11 +348,13 @@ public class ProcessBuilderForWin32 { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String,String> environment() { |
|
|
|
public Map<String,String> environment() { |
|
|
|
SecurityManager security = System.getSecurityManager(); |
|
|
|
SecurityManager security = System.getSecurityManager(); |
|
|
|
if (security != null) |
|
|
|
if (security != null) { |
|
|
|
security.checkPermission(new RuntimePermission("getenv.*")); |
|
|
|
security.checkPermission(new RuntimePermission("getenv.*")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (environment == null) |
|
|
|
if (environment == null) { |
|
|
|
environment = ProcessEnvironmentForWin32.environment(); |
|
|
|
environment = ProcessEnvironmentForWin32.environment(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assert environment != null; |
|
|
|
assert environment != null; |
|
|
|
|
|
|
|
|
|
|
@ -369,15 +375,17 @@ public class ProcessBuilderForWin32 { |
|
|
|
// for compatibility with old broken code.
|
|
|
|
// for compatibility with old broken code.
|
|
|
|
|
|
|
|
|
|
|
|
// Silently discard any trailing junk.
|
|
|
|
// Silently discard any trailing junk.
|
|
|
|
if (envstring.indexOf((int) '\u0000') != -1) |
|
|
|
if (envstring.indexOf((int) '\u0000') != -1) { |
|
|
|
envstring = envstring.replaceFirst("\u0000.*", ""); |
|
|
|
envstring = envstring.replaceFirst("\u0000.*", ""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int eqlsign = |
|
|
|
int eqlsign = |
|
|
|
envstring.indexOf('=', ProcessEnvironmentForWin32.MIN_NAME_LENGTH); |
|
|
|
envstring.indexOf('=', ProcessEnvironmentForWin32.MIN_NAME_LENGTH); |
|
|
|
// Silently ignore envstrings lacking the required `='.
|
|
|
|
// Silently ignore envstrings lacking the required `='.
|
|
|
|
if (eqlsign != -1) |
|
|
|
if (eqlsign != -1) { |
|
|
|
environment.put(envstring.substring(0,eqlsign), |
|
|
|
environment.put(envstring.substring(0,eqlsign), |
|
|
|
envstring.substring(eqlsign+1)); |
|
|
|
envstring.substring(eqlsign+1)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return this; |
|
|
|
return this; |
|
|
@ -425,6 +433,7 @@ public class ProcessBuilderForWin32 { |
|
|
|
static class NullInputStream extends InputStream { |
|
|
|
static class NullInputStream extends InputStream { |
|
|
|
static final ProcessBuilderForWin32.NullInputStream INSTANCE = new ProcessBuilderForWin32.NullInputStream(); |
|
|
|
static final ProcessBuilderForWin32.NullInputStream INSTANCE = new ProcessBuilderForWin32.NullInputStream(); |
|
|
|
private NullInputStream() {} |
|
|
|
private NullInputStream() {} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int read() { return -1; } |
|
|
|
public int read() { return -1; } |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int available() { return 0; } |
|
|
|
public int available() { return 0; } |
|
|
@ -436,6 +445,7 @@ public class ProcessBuilderForWin32 { |
|
|
|
static class NullOutputStream extends OutputStream { |
|
|
|
static class NullOutputStream extends OutputStream { |
|
|
|
static final ProcessBuilderForWin32.NullOutputStream INSTANCE = new ProcessBuilderForWin32.NullOutputStream(); |
|
|
|
static final ProcessBuilderForWin32.NullOutputStream INSTANCE = new ProcessBuilderForWin32.NullOutputStream(); |
|
|
|
private NullOutputStream() {} |
|
|
|
private NullOutputStream() {} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void write(int b) throws IOException { |
|
|
|
public void write(int b) throws IOException { |
|
|
|
throw new IOException("Stream closed"); |
|
|
|
throw new IOException("Stream closed"); |
|
|
|
} |
|
|
|
} |
|
|
@ -516,7 +526,9 @@ public class ProcessBuilderForWin32 { |
|
|
|
* }</pre> |
|
|
|
* }</pre> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static final ProcessBuilderForWin32.Redirect PIPE = new ProcessBuilderForWin32.Redirect() { |
|
|
|
public static final ProcessBuilderForWin32.Redirect PIPE = new ProcessBuilderForWin32.Redirect() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Type type() { return Type.PIPE; } |
|
|
|
public Type type() { return Type.PIPE; } |
|
|
|
|
|
|
|
@Override |
|
|
|
public String toString() { return type().toString(); }}; |
|
|
|
public String toString() { return type().toString(); }}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -531,7 +543,9 @@ public class ProcessBuilderForWin32 { |
|
|
|
* }</pre> |
|
|
|
* }</pre> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static final ProcessBuilderForWin32.Redirect INHERIT = new ProcessBuilderForWin32.Redirect() { |
|
|
|
public static final ProcessBuilderForWin32.Redirect INHERIT = new ProcessBuilderForWin32.Redirect() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Type type() { return Type.INHERIT; } |
|
|
|
public Type type() { return Type.INHERIT; } |
|
|
|
|
|
|
|
@Override |
|
|
|
public String toString() { return type().toString(); }}; |
|
|
|
public String toString() { return type().toString(); }}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -565,12 +579,15 @@ public class ProcessBuilderForWin32 { |
|
|
|
* @return a redirect to read from the specified file |
|
|
|
* @return a redirect to read from the specified file |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static ProcessBuilderForWin32.Redirect from(final File file) { |
|
|
|
public static ProcessBuilderForWin32.Redirect from(final File file) { |
|
|
|
if (file == null) |
|
|
|
if (file == null) { |
|
|
|
throw new NullPointerException(); |
|
|
|
throw new NullPointerException(); |
|
|
|
|
|
|
|
} |
|
|
|
return new ProcessBuilderForWin32.Redirect() { |
|
|
|
return new ProcessBuilderForWin32.Redirect() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Type type() { return Type.READ; } |
|
|
|
public Type type() { return Type.READ; } |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public File file() { return file; } |
|
|
|
public File file() { return file; } |
|
|
|
|
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return "redirect to read from file \"" + file + "\""; |
|
|
|
return "redirect to read from file \"" + file + "\""; |
|
|
|
} |
|
|
|
} |
|
|
@ -593,12 +610,15 @@ public class ProcessBuilderForWin32 { |
|
|
|
* @return a redirect to write to the specified file |
|
|
|
* @return a redirect to write to the specified file |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static ProcessBuilderForWin32.Redirect to(final File file) { |
|
|
|
public static ProcessBuilderForWin32.Redirect to(final File file) { |
|
|
|
if (file == null) |
|
|
|
if (file == null) { |
|
|
|
throw new NullPointerException(); |
|
|
|
throw new NullPointerException(); |
|
|
|
|
|
|
|
} |
|
|
|
return new ProcessBuilderForWin32.Redirect() { |
|
|
|
return new ProcessBuilderForWin32.Redirect() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Type type() { return Type.WRITE; } |
|
|
|
public Type type() { return Type.WRITE; } |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public File file() { return file; } |
|
|
|
public File file() { return file; } |
|
|
|
|
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return "redirect to write to file \"" + file + "\""; |
|
|
|
return "redirect to write to file \"" + file + "\""; |
|
|
|
} |
|
|
|
} |
|
|
@ -626,12 +646,15 @@ public class ProcessBuilderForWin32 { |
|
|
|
* @return a redirect to append to the specified file |
|
|
|
* @return a redirect to append to the specified file |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static ProcessBuilderForWin32.Redirect appendTo(final File file) { |
|
|
|
public static ProcessBuilderForWin32.Redirect appendTo(final File file) { |
|
|
|
if (file == null) |
|
|
|
if (file == null) { |
|
|
|
throw new NullPointerException(); |
|
|
|
throw new NullPointerException(); |
|
|
|
|
|
|
|
} |
|
|
|
return new ProcessBuilderForWin32.Redirect() { |
|
|
|
return new ProcessBuilderForWin32.Redirect() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Type type() { return Type.APPEND; } |
|
|
|
public Type type() { return Type.APPEND; } |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public File file() { return file; } |
|
|
|
public File file() { return file; } |
|
|
|
|
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return "redirect to append to file \"" + file + "\""; |
|
|
|
return "redirect to append to file \"" + file + "\""; |
|
|
|
} |
|
|
|
} |
|
|
@ -647,14 +670,18 @@ public class ProcessBuilderForWin32 { |
|
|
|
* instances of the same type associated with non-null equal |
|
|
|
* instances of the same type associated with non-null equal |
|
|
|
* {@code File} instances. |
|
|
|
* {@code File} instances. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean equals(Object obj) { |
|
|
|
public boolean equals(Object obj) { |
|
|
|
if (obj == this) |
|
|
|
if (obj == this) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
if (! (obj instanceof ProcessBuilderForWin32.Redirect)) |
|
|
|
} |
|
|
|
|
|
|
|
if (! (obj instanceof ProcessBuilderForWin32.Redirect)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
ProcessBuilderForWin32.Redirect r = (ProcessBuilderForWin32.Redirect) obj; |
|
|
|
ProcessBuilderForWin32.Redirect r = (ProcessBuilderForWin32.Redirect) obj; |
|
|
|
if (r.type() != this.type()) |
|
|
|
if (r.type() != this.type()) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
assert this.file() != null; |
|
|
|
assert this.file() != null; |
|
|
|
return this.file().equals(r.file()); |
|
|
|
return this.file().equals(r.file()); |
|
|
|
} |
|
|
|
} |
|
|
@ -663,12 +690,14 @@ public class ProcessBuilderForWin32 { |
|
|
|
* Returns a hash code value for this {@code Redirect}. |
|
|
|
* Returns a hash code value for this {@code Redirect}. |
|
|
|
* @return a hash code value for this {@code Redirect} |
|
|
|
* @return a hash code value for this {@code Redirect} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
public int hashCode() { |
|
|
|
public int hashCode() { |
|
|
|
File file = file(); |
|
|
|
File file = file(); |
|
|
|
if (file == null) |
|
|
|
if (file == null) { |
|
|
|
return super.hashCode(); |
|
|
|
return super.hashCode(); |
|
|
|
else |
|
|
|
} else { |
|
|
|
return file.hashCode(); |
|
|
|
return file.hashCode(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -679,10 +708,11 @@ public class ProcessBuilderForWin32 { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ProcessBuilderForWin32.Redirect[] redirects() { |
|
|
|
private ProcessBuilderForWin32.Redirect[] redirects() { |
|
|
|
if (redirects == null) |
|
|
|
if (redirects == null) { |
|
|
|
redirects = new ProcessBuilderForWin32.Redirect[] { |
|
|
|
redirects = new Redirect[] { |
|
|
|
ProcessBuilderForWin32.Redirect.PIPE, ProcessBuilderForWin32.Redirect.PIPE, ProcessBuilderForWin32.Redirect.PIPE |
|
|
|
Redirect.PIPE, Redirect.PIPE, Redirect.PIPE |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
return redirects; |
|
|
|
return redirects; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -711,9 +741,10 @@ public class ProcessBuilderForWin32 { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ProcessBuilderForWin32 redirectInput(ProcessBuilderForWin32.Redirect source) { |
|
|
|
public ProcessBuilderForWin32 redirectInput(ProcessBuilderForWin32.Redirect source) { |
|
|
|
if (source.type() == ProcessBuilderForWin32.Redirect.Type.WRITE || |
|
|
|
if (source.type() == ProcessBuilderForWin32.Redirect.Type.WRITE || |
|
|
|
source.type() == ProcessBuilderForWin32.Redirect.Type.APPEND) |
|
|
|
source.type() == ProcessBuilderForWin32.Redirect.Type.APPEND) { |
|
|
|
throw new IllegalArgumentException( |
|
|
|
throw new IllegalArgumentException( |
|
|
|
"Redirect invalid for reading: " + source); |
|
|
|
"Redirect invalid for reading: " + source); |
|
|
|
|
|
|
|
} |
|
|
|
redirects()[0] = source; |
|
|
|
redirects()[0] = source; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
@ -741,9 +772,10 @@ public class ProcessBuilderForWin32 { |
|
|
|
* @since 1.7 |
|
|
|
* @since 1.7 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ProcessBuilderForWin32 redirectOutput(ProcessBuilderForWin32.Redirect destination) { |
|
|
|
public ProcessBuilderForWin32 redirectOutput(ProcessBuilderForWin32.Redirect destination) { |
|
|
|
if (destination.type() == ProcessBuilderForWin32.Redirect.Type.READ) |
|
|
|
if (destination.type() == ProcessBuilderForWin32.Redirect.Type.READ) { |
|
|
|
throw new IllegalArgumentException( |
|
|
|
throw new IllegalArgumentException( |
|
|
|
"Redirect invalid for writing: " + destination); |
|
|
|
"Redirect invalid for writing: " + destination); |
|
|
|
|
|
|
|
} |
|
|
|
redirects()[1] = destination; |
|
|
|
redirects()[1] = destination; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
@ -775,9 +807,10 @@ public class ProcessBuilderForWin32 { |
|
|
|
* @since 1.7 |
|
|
|
* @since 1.7 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ProcessBuilderForWin32 redirectError(ProcessBuilderForWin32.Redirect destination) { |
|
|
|
public ProcessBuilderForWin32 redirectError(ProcessBuilderForWin32.Redirect destination) { |
|
|
|
if (destination.type() == ProcessBuilderForWin32.Redirect.Type.READ) |
|
|
|
if (destination.type() == ProcessBuilderForWin32.Redirect.Type.READ) { |
|
|
|
throw new IllegalArgumentException( |
|
|
|
throw new IllegalArgumentException( |
|
|
|
"Redirect invalid for writing: " + destination); |
|
|
|
"Redirect invalid for writing: " + destination); |
|
|
|
|
|
|
|
} |
|
|
|
redirects()[2] = destination; |
|
|
|
redirects()[2] = destination; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
@ -1019,15 +1052,18 @@ public class ProcessBuilderForWin32 { |
|
|
|
String[] cmdarray = command.toArray(new String[command.size()]); |
|
|
|
String[] cmdarray = command.toArray(new String[command.size()]); |
|
|
|
cmdarray = cmdarray.clone(); |
|
|
|
cmdarray = cmdarray.clone(); |
|
|
|
|
|
|
|
|
|
|
|
for (String arg : cmdarray) |
|
|
|
for (String arg : cmdarray) { |
|
|
|
if (arg == null) |
|
|
|
if (arg == null) { |
|
|
|
throw new NullPointerException(); |
|
|
|
throw new NullPointerException(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// Throws IndexOutOfBoundsException if command is empty
|
|
|
|
// Throws IndexOutOfBoundsException if command is empty
|
|
|
|
String prog = cmdarray[0]; |
|
|
|
String prog = cmdarray[0]; |
|
|
|
|
|
|
|
|
|
|
|
SecurityManager security = System.getSecurityManager(); |
|
|
|
SecurityManager security = System.getSecurityManager(); |
|
|
|
if (security != null) |
|
|
|
if (security != null) { |
|
|
|
security.checkExec(prog); |
|
|
|
security.checkExec(prog); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String dir = directory == null ? null : directory.toString(); |
|
|
|
String dir = directory == null ? null : directory.toString(); |
|
|
|
|
|
|
|
|
|
|
|