|
Lines 66-71
Link Here
|
| 66 |
OutputStream out; |
66 |
OutputStream out; |
| 67 |
InputStream in; |
67 |
InputStream in; |
| 68 |
InputStream err; |
68 |
InputStream err; |
|
|
69 |
private PTY fPty; |
| 69 |
|
70 |
|
| 70 |
public Spawner(String command, boolean bNoRedirect) throws IOException { |
71 |
public Spawner(String command, boolean bNoRedirect) throws IOException { |
| 71 |
StringTokenizer tokenizer = new StringTokenizer(command); |
72 |
StringTokenizer tokenizer = new StringTokenizer(command); |
|
Lines 92-97
Link Here
|
| 92 |
String dirpath = "."; //$NON-NLS-1$ |
93 |
String dirpath = "."; //$NON-NLS-1$ |
| 93 |
if (dir != null) |
94 |
if (dir != null) |
| 94 |
dirpath = dir.getAbsolutePath(); |
95 |
dirpath = dir.getAbsolutePath(); |
|
|
96 |
fPty = pty; |
| 95 |
exec_pty(cmdarray, envp, dirpath, pty); |
97 |
exec_pty(cmdarray, envp, dirpath, pty); |
| 96 |
} |
98 |
} |
| 97 |
/** |
99 |
/** |
|
Lines 144-151
Link Here
|
| 144 |
**/ |
146 |
**/ |
| 145 |
@Override |
147 |
@Override |
| 146 |
public InputStream getInputStream() { |
148 |
public InputStream getInputStream() { |
| 147 |
if(null == in) |
149 |
if(null == in) { |
| 148 |
in = new SpawnerInputStream(fChannels[1]); |
150 |
if (fPty != null) { |
|
|
151 |
in = fPty.getInputStream(); |
| 152 |
} else { |
| 153 |
in = new SpawnerInputStream(fChannels[1]); |
| 154 |
} |
| 155 |
} |
| 149 |
return in; |
156 |
return in; |
| 150 |
} |
157 |
} |
| 151 |
|
158 |
|
|
Lines 154-161
Link Here
|
| 154 |
**/ |
161 |
**/ |
| 155 |
@Override |
162 |
@Override |
| 156 |
public OutputStream getOutputStream() { |
163 |
public OutputStream getOutputStream() { |
| 157 |
if(null == out) |
164 |
if(null == out) { |
| 158 |
out = new SpawnerOutputStream(fChannels[0]); |
165 |
if (fPty != null) { |
|
|
166 |
out = fPty.getOutputStream(); |
| 167 |
} else { |
| 168 |
out = new SpawnerOutputStream(fChannels[0]); |
| 169 |
} |
| 170 |
} |
| 159 |
return out; |
171 |
return out; |
| 160 |
} |
172 |
} |
| 161 |
|
173 |
|
|
Lines 165-171
Link Here
|
| 165 |
@Override |
177 |
@Override |
| 166 |
public InputStream getErrorStream() { |
178 |
public InputStream getErrorStream() { |
| 167 |
if(null == err) |
179 |
if(null == err) |
| 168 |
err = new SpawnerInputStream(fChannels[2]); |
180 |
if (fPty != null && !fPty.isConsole()) { |
|
|
181 |
// If PTY is used and it's not in "Console" mode, then stderr is |
| 182 |
// redirected to the PTY's output stream. Therefore, return a |
| 183 |
// dummy stream for error stream. |
| 184 |
err = new InputStream() { |
| 185 |
boolean fClosed = false; |
| 186 |
@Override |
| 187 |
public synchronized int read() throws IOException { |
| 188 |
while (!fClosed) { |
| 189 |
try { |
| 190 |
wait(); |
| 191 |
} catch (InterruptedException e) {} |
| 192 |
} |
| 193 |
return -1; |
| 194 |
} |
| 195 |
|
| 196 |
@Override |
| 197 |
public void close() throws IOException { |
| 198 |
synchronized(this) { |
| 199 |
fClosed = true; |
| 200 |
notifyAll(); |
| 201 |
} |
| 202 |
super.close(); |
| 203 |
} |
| 204 |
}; |
| 205 |
} else { |
| 206 |
err = new SpawnerInputStream(fChannels[2]); |
| 207 |
} |
| 169 |
return err; |
208 |
return err; |
| 170 |
} |
209 |
} |
| 171 |
|
210 |
|
|
Lines 179-190
Link Here
|
| 179 |
} |
218 |
} |
| 180 |
try { |
219 |
try { |
| 181 |
if(null == err) |
220 |
if(null == err) |
| 182 |
((SpawnerInputStream)getErrorStream()).close(); |
221 |
getErrorStream().close(); |
| 183 |
if(null == in) |
222 |
if(null == in) |
| 184 |
((SpawnerInputStream)getInputStream()).close(); |
223 |
getInputStream().close(); |
| 185 |
if(null == out) |
224 |
if(null == out) |
| 186 |
((SpawnerOutputStream)getOutputStream()).close(); |
225 |
getOutputStream().close(); |
| 187 |
|
|
|
| 188 |
} catch (IOException e) { |
226 |
} catch (IOException e) { |
| 189 |
} |
227 |
} |
| 190 |
return status; |
228 |
return status; |
|
Lines 211-221
Link Here
|
| 211 |
// Close the streams on this side. |
249 |
// Close the streams on this side. |
| 212 |
try { |
250 |
try { |
| 213 |
if(null == err) |
251 |
if(null == err) |
| 214 |
((SpawnerInputStream)getErrorStream()).close(); |
252 |
getErrorStream().close(); |
| 215 |
if(null == in) |
253 |
if(null == in) |
| 216 |
((SpawnerInputStream)getInputStream()).close(); |
254 |
getInputStream().close(); |
| 217 |
if(null == out) |
255 |
if(null == out) |
| 218 |
((SpawnerOutputStream)getOutputStream()).close(); |
256 |
getOutputStream().close(); |
| 219 |
} catch (IOException e) { |
257 |
} catch (IOException e) { |
| 220 |
} |
258 |
} |
| 221 |
// Grace before using the heavy gone. |
259 |
// Grace before using the heavy gone. |