- Timestamp:
- 09/23/13 18:54:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/running/ExternalProcess.java
r105 r107 8 8 import java.io.PrintWriter; 9 9 import java.util.ArrayList; 10 import java.util.Arrays; 10 11 import java.util.List; 11 12 … … 31 32 import com.framsticks.util.dispatching.ThrowExceptionHandler; 32 33 import com.framsticks.util.io.Encoding; 34 import com.framsticks.util.lang.Strings; 33 35 34 36 @FramsClassAnnotation … … 38 40 protected List<String> arguments = new ArrayList<>(); 39 41 protected Process process; 40 protected final ProcessBuilder builder = new ProcessBuilder();41 42 protected Thread<ExternalProcess> readerThread = new Thread<ExternalProcess>(); 42 43 … … 45 46 protected Integer exitCode; 46 47 protected String echoInput; 48 protected String directory; 49 protected String host; 47 50 48 51 protected final EventListeners<ValueChange> listeners = new EventListeners<>(); … … 70 73 setName("process"); 71 74 arguments.add(null); 72 builder.redirectErrorStream(true);73 75 } 74 76 … … 120 122 @ParamAnnotation(flags = ParamFlags.USERREADONLY) 121 123 public void setDirectory(String directory) { 122 builder.directory(new File(directory)); 124 this.directory = directory; 125 } 126 127 /** 128 * @return the host 129 */ 130 public String getHost() { 131 return host; 132 } 133 134 /** 135 * @param host the host to set 136 */ 137 public void setHost(String host) { 138 this.host = host; 123 139 } 124 140 125 141 @ParamAnnotation 126 142 public String getDirectory() { 127 return builder.directory() != null ? builder.directory().getName() : ".";143 return Strings.toStringNullProof(directory, "."); 128 144 } 129 145 130 146 @Override 131 147 protected void joinableStart() { 148 149 final ProcessBuilder builder = new ProcessBuilder(); 150 151 builder.redirectErrorStream(true); 152 if (host == null) { 153 setDirectory(System.getProperties().get("user.home") + "/" + getDirectory()); 154 setCommand(getDirectory() + "/" + getCommand()); 155 builder.directory(new File(getDirectory())); 156 } else { 157 StringBuilder b = new StringBuilder(); 158 setCommand("./" + getCommand()); 159 for (String a : arguments) { 160 b.append(" '").append(a).append("'"); 161 } 162 arguments = Arrays.asList("ssh", host, "-tt", ("cd " + getDirectory() + " &&" + b.toString())); 163 } 132 164 log.info("running process {}", this); 165 133 166 builder.command(arguments); 134 167 try {
Note: See TracChangeset
for help on using the changeset viewer.