node-pty 1.0.0 → 1.1.0-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +2 -0
- package/lib/windowsPtyAgent.js +6 -7
- package/lib/windowsPtyAgent.js.map +1 -1
- package/lib/windowsTerminal.test.js +98 -96
- package/lib/windowsTerminal.test.js.map +1 -1
- package/package.json +1 -1
- package/src/native.d.ts +3 -4
- package/src/win/conpty.cc +20 -16
- package/src/win/conpty_console_list.cc +3 -3
- package/src/win/path_util.cc +21 -2
- package/src/win/path_util.h +1 -0
- package/src/win/winpty.cc +118 -54
- package/src/windowsPtyAgent.ts +6 -7
- package/src/windowsTerminal.test.ts +99 -97
package/binding.gyp
CHANGED
package/lib/windowsPtyAgent.js
CHANGED
|
@@ -31,7 +31,6 @@ var WindowsPtyAgent = /** @class */ (function () {
|
|
|
31
31
|
this._useConpty = _useConpty;
|
|
32
32
|
this._pid = 0;
|
|
33
33
|
this._innerPid = 0;
|
|
34
|
-
this._innerPidHandle = 0;
|
|
35
34
|
if (this._useConpty === undefined || this._useConpty === true) {
|
|
36
35
|
this._useConpty = this._getWindowsBuildNumber() >= 18309;
|
|
37
36
|
}
|
|
@@ -83,7 +82,6 @@ var WindowsPtyAgent = /** @class */ (function () {
|
|
|
83
82
|
term = this._ptyNative.startProcess(file, commandLine, env, cwd, cols, rows, debug);
|
|
84
83
|
this._pid = term.pid;
|
|
85
84
|
this._innerPid = term.innerPid;
|
|
86
|
-
this._innerPidHandle = term.innerPidHandle;
|
|
87
85
|
}
|
|
88
86
|
// Not available on windows.
|
|
89
87
|
this._fd = term.fd;
|
|
@@ -172,14 +170,14 @@ var WindowsPtyAgent = /** @class */ (function () {
|
|
|
172
170
|
});
|
|
173
171
|
}
|
|
174
172
|
else {
|
|
175
|
-
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
// dropped, we want to immediately kill the entire console process list.
|
|
173
|
+
// Because pty.kill closes the handle, it will kill most processes by itself.
|
|
174
|
+
// Process IDs can be reused as soon as all handles to them are
|
|
175
|
+
// dropped, so we want to immediately kill the entire console process list.
|
|
179
176
|
// If we do not force kill all processes here, node servers in particular
|
|
180
177
|
// seem to become detached and remain running (see
|
|
181
178
|
// Microsoft/vscode#26807).
|
|
182
179
|
var processList = this._ptyNative.getProcessList(this._pid);
|
|
180
|
+
this._ptyNative.kill(this._pid, this._innerPid);
|
|
183
181
|
processList.forEach(function (pid) {
|
|
184
182
|
try {
|
|
185
183
|
process.kill(pid);
|
|
@@ -211,7 +209,8 @@ var WindowsPtyAgent = /** @class */ (function () {
|
|
|
211
209
|
if (this._useConpty) {
|
|
212
210
|
return this._exitCode;
|
|
213
211
|
}
|
|
214
|
-
|
|
212
|
+
var winptyExitCode = this._ptyNative.getExitCode(this._innerPid);
|
|
213
|
+
return winptyExitCode === -1 ? undefined : winptyExitCode;
|
|
215
214
|
},
|
|
216
215
|
enumerable: false,
|
|
217
216
|
configurable: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windowsPtyAgent.js","sourceRoot":"","sources":["../src/windowsPtyAgent.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,uBAAyB;AACzB,uBAAyB;AACzB,2BAA6B;AAC7B,2BAA6B;AAE7B,+CAAqC;AACrC,qEAA6D;AAE7D,IAAI,YAA2B,CAAC;AAChC,IAAI,YAA2B,CAAC;AAEhC;;;;GAIG;AACH,IAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC;;;GAGG;AACH;
|
|
1
|
+
{"version":3,"file":"windowsPtyAgent.js","sourceRoot":"","sources":["../src/windowsPtyAgent.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,uBAAyB;AACzB,uBAAyB;AACzB,2BAA6B;AAC7B,2BAA6B;AAE7B,+CAAqC;AACrC,qEAA6D;AAE7D,IAAI,YAA2B,CAAC;AAChC,IAAI,YAA2B,CAAC;AAEhC;;;;GAIG;AACH,IAAM,mBA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C,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;QAC9B,MAAM,IAAI,IAAI,CAAC;KAChB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,GAAG,CAAC,IAAa,EAAE,IAAa;IACvC,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -84,117 +84,119 @@ function pollForProcessTreeSize(pid, size, intervalMs, timeoutMs) {
|
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
if (process.platform === 'win32') {
|
|
87
|
-
|
|
88
|
-
describe(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Add done call to deferred function queue to ensure the kill call has completed
|
|
93
|
-
term._defer(done);
|
|
94
|
-
});
|
|
95
|
-
it('should kill the process tree', function (done) {
|
|
96
|
-
this.timeout(5000);
|
|
97
|
-
var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', [], {});
|
|
98
|
-
// Start sub-processes
|
|
99
|
-
term.write('powershell.exe\r');
|
|
100
|
-
term.write('notepad.exe\r');
|
|
101
|
-
term.write('node.exe\r');
|
|
102
|
-
pollForProcessTreeSize(term.pid, 4, 500, 5000).then(function (list) {
|
|
103
|
-
assert.strictEqual(list[0].name.toLowerCase(), 'cmd.exe');
|
|
104
|
-
assert.strictEqual(list[1].name.toLowerCase(), 'powershell.exe');
|
|
105
|
-
assert.strictEqual(list[2].name.toLowerCase(), 'notepad.exe');
|
|
106
|
-
assert.strictEqual(list[3].name.toLowerCase(), 'node.exe');
|
|
87
|
+
[true, false].forEach(function (useConpty) {
|
|
88
|
+
describe("WindowsTerminal (useConpty = " + useConpty + ")", function () {
|
|
89
|
+
describe('kill', function () {
|
|
90
|
+
it('should not crash parent process', function (done) {
|
|
91
|
+
var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', [], { useConpty: useConpty });
|
|
107
92
|
term.kill();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
93
|
+
// Add done call to deferred function queue to ensure the kill call has completed
|
|
94
|
+
term._defer(done);
|
|
95
|
+
});
|
|
96
|
+
it('should kill the process tree', function (done) {
|
|
97
|
+
this.timeout(5000);
|
|
98
|
+
var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', [], { useConpty: useConpty });
|
|
99
|
+
// Start sub-processes
|
|
100
|
+
term.write('powershell.exe\r');
|
|
101
|
+
term.write('notepad.exe\r');
|
|
102
|
+
term.write('node.exe\r');
|
|
103
|
+
pollForProcessTreeSize(term.pid, 4, 500, 5000).then(function (list) {
|
|
104
|
+
assert.strictEqual(list[0].name.toLowerCase(), 'cmd.exe');
|
|
105
|
+
assert.strictEqual(list[1].name.toLowerCase(), 'powershell.exe');
|
|
106
|
+
assert.strictEqual(list[2].name.toLowerCase(), 'notepad.exe');
|
|
107
|
+
assert.strictEqual(list[3].name.toLowerCase(), 'node.exe');
|
|
108
|
+
term.kill();
|
|
109
|
+
var desiredState = {};
|
|
110
|
+
desiredState[list[0].pid] = false;
|
|
111
|
+
desiredState[list[1].pid] = false;
|
|
112
|
+
desiredState[list[2].pid] = true;
|
|
113
|
+
desiredState[list[3].pid] = false;
|
|
114
|
+
pollForProcessState(desiredState).then(function () {
|
|
115
|
+
// Kill notepad before done
|
|
116
|
+
process.kill(list[2].pid);
|
|
117
|
+
done();
|
|
118
|
+
});
|
|
117
119
|
});
|
|
118
120
|
});
|
|
119
121
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
describe('resize', function () {
|
|
123
|
+
it('should throw a non-native exception when resizing an invalid value', function () {
|
|
124
|
+
var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', [], { useConpty: useConpty });
|
|
125
|
+
assert.throws(function () { return term.resize(-1, -1); });
|
|
126
|
+
assert.throws(function () { return term.resize(0, 0); });
|
|
127
|
+
assert.doesNotThrow(function () { return term.resize(1, 1); });
|
|
128
|
+
});
|
|
129
|
+
it('should throw a non-native exception when resizing a killed terminal', function (done) {
|
|
130
|
+
var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', [], { useConpty: useConpty });
|
|
131
|
+
term._defer(function () {
|
|
132
|
+
term.on('exit', function () {
|
|
133
|
+
assert.throws(function () { return term.resize(1, 1); });
|
|
134
|
+
done();
|
|
135
|
+
});
|
|
136
|
+
term.destroy();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
127
139
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
140
|
+
describe('Args as CommandLine', function () {
|
|
141
|
+
it('should not fail running a file containing a space in the path', function (done) {
|
|
142
|
+
var spaceFolder = path.resolve(__dirname, '..', 'fixtures', 'space folder');
|
|
143
|
+
if (!fs.existsSync(spaceFolder)) {
|
|
144
|
+
fs.mkdirSync(spaceFolder);
|
|
145
|
+
}
|
|
146
|
+
var cmdCopiedPath = path.resolve(spaceFolder, 'cmd.exe');
|
|
147
|
+
var data = fs.readFileSync(process.env.windir + "\\System32\\cmd.exe");
|
|
148
|
+
fs.writeFileSync(cmdCopiedPath, data);
|
|
149
|
+
if (!fs.existsSync(cmdCopiedPath)) {
|
|
150
|
+
// Skip test if git bash isn't installed
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
var term = new windowsTerminal_1.WindowsTerminal(cmdCopiedPath, '/c echo "hello world"', { useConpty: useConpty });
|
|
154
|
+
var result = '';
|
|
155
|
+
term.on('data', function (data) {
|
|
156
|
+
result += data;
|
|
157
|
+
});
|
|
131
158
|
term.on('exit', function () {
|
|
132
|
-
assert.
|
|
159
|
+
assert.ok(result.indexOf('hello world') >= 1);
|
|
133
160
|
done();
|
|
134
161
|
});
|
|
135
|
-
term.destroy();
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
describe('Args as CommandLine', function () {
|
|
140
|
-
it('should not fail running a file containing a space in the path', function (done) {
|
|
141
|
-
var spaceFolder = path.resolve(__dirname, '..', 'fixtures', 'space folder');
|
|
142
|
-
if (!fs.existsSync(spaceFolder)) {
|
|
143
|
-
fs.mkdirSync(spaceFolder);
|
|
144
|
-
}
|
|
145
|
-
var cmdCopiedPath = path.resolve(spaceFolder, 'cmd.exe');
|
|
146
|
-
var data = fs.readFileSync(process.env.windir + "\\System32\\cmd.exe");
|
|
147
|
-
fs.writeFileSync(cmdCopiedPath, data);
|
|
148
|
-
if (!fs.existsSync(cmdCopiedPath)) {
|
|
149
|
-
// Skip test if git bash isn't installed
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
var term = new windowsTerminal_1.WindowsTerminal(cmdCopiedPath, '/c echo "hello world"', {});
|
|
153
|
-
var result = '';
|
|
154
|
-
term.on('data', function (data) {
|
|
155
|
-
result += data;
|
|
156
|
-
});
|
|
157
|
-
term.on('exit', function () {
|
|
158
|
-
assert.ok(result.indexOf('hello world') >= 1);
|
|
159
|
-
done();
|
|
160
162
|
});
|
|
161
163
|
});
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
164
|
+
describe('env', function () {
|
|
165
|
+
it('should set environment variables of the shell', function (done) {
|
|
166
|
+
var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', '/C echo %FOO%', { env: { FOO: 'BAR' } });
|
|
167
|
+
var result = '';
|
|
168
|
+
term.on('data', function (data) {
|
|
169
|
+
result += data;
|
|
170
|
+
});
|
|
171
|
+
term.on('exit', function () {
|
|
172
|
+
assert.ok(result.indexOf('BAR') >= 0);
|
|
173
|
+
done();
|
|
174
|
+
});
|
|
173
175
|
});
|
|
174
176
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
177
|
+
describe('On close', function () {
|
|
178
|
+
it('should return process zero exit codes', function (done) {
|
|
179
|
+
var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', '/C exit', { useConpty: useConpty });
|
|
180
|
+
term.on('exit', function (code) {
|
|
181
|
+
assert.strictEqual(code, 0);
|
|
182
|
+
done();
|
|
183
|
+
});
|
|
182
184
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
it('should return process non-zero exit codes', function (done) {
|
|
186
|
+
var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', '/C exit 2', { useConpty: useConpty });
|
|
187
|
+
term.on('exit', function (code) {
|
|
188
|
+
assert.strictEqual(code, 2);
|
|
189
|
+
done();
|
|
190
|
+
});
|
|
189
191
|
});
|
|
190
192
|
});
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
describe('Write', function () {
|
|
194
|
+
it('should accept input', function (done) {
|
|
195
|
+
var term = new windowsTerminal_1.WindowsTerminal('cmd.exe', '', { useConpty: useConpty });
|
|
196
|
+
term.write('exit\r');
|
|
197
|
+
term.on('exit', function () {
|
|
198
|
+
done();
|
|
199
|
+
});
|
|
198
200
|
});
|
|
199
201
|
});
|
|
200
202
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"windowsTerminal.test.js","sourceRoot":"","sources":["../src/windowsTerminal.test.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,uBAAyB;AACzB,+BAAiC;AACjC,qDAAoD;AACpD,2BAA6B;AAC7B,gCAAkC;AAYlC,SAAS,mBAAmB,CAAC,YAA2B,EAAE,UAAwB,EAAE,SAAwB;IAAlD,2BAAA,EAAA,gBAAwB;IAAE,0BAAA,EAAA,gBAAwB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SAAS,EAAE,EAAE,EAAE,EAAE,SAAS,WAAA,EAAE,CAAC,CAAC;oBAC/D,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBACrB,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE;wBACd,IAAI,EAAE,CAAC;oBACT,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;CACJ"}
|
package/package.json
CHANGED
package/src/native.d.ts
CHANGED
|
@@ -12,10 +12,10 @@ interface IConptyNative {
|
|
|
12
12
|
|
|
13
13
|
interface IWinptyNative {
|
|
14
14
|
startProcess(file: string, commandLine: string, env: string[], cwd: string, cols: number, rows: number, debug: boolean): IWinptyProcess;
|
|
15
|
-
resize(
|
|
16
|
-
kill(pid: number,
|
|
15
|
+
resize(pid: number, cols: number, rows: number): void;
|
|
16
|
+
kill(pid: number, innerPid: number): void;
|
|
17
17
|
getProcessList(pid: number): number[];
|
|
18
|
-
getExitCode(
|
|
18
|
+
getExitCode(innerPid: number): number;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
interface IUnixNative {
|
|
@@ -40,7 +40,6 @@ interface IWinptyProcess {
|
|
|
40
40
|
conout: string;
|
|
41
41
|
pid: number;
|
|
42
42
|
innerPid: number;
|
|
43
|
-
innerPidHandle: number;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
interface IUnixProcess {
|
package/src/win/conpty.cc
CHANGED
|
@@ -179,8 +179,8 @@ static NAN_METHOD(PtyStartProcess) {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
const std::wstring filename(path_util::to_wstring(Nan::Utf8String(info[0])));
|
|
182
|
-
const SHORT cols = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust();
|
|
183
|
-
const SHORT rows = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust();
|
|
182
|
+
const SHORT cols = static_cast<SHORT>(info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust());
|
|
183
|
+
const SHORT rows = static_cast<SHORT>(info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust());
|
|
184
184
|
const bool debug = Nan::To<bool>(info[3]).FromJust();
|
|
185
185
|
const std::wstring pipeName(path_util::to_wstring(Nan::Utf8String(info[4])));
|
|
186
186
|
const bool inheritCursor = Nan::To<bool>(info[5]).FromJust();
|
|
@@ -194,12 +194,10 @@ static NAN_METHOD(PtyStartProcess) {
|
|
|
194
194
|
shellpath = filename;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
std::string shellpath_(shellpath.begin(), shellpath.end());
|
|
198
|
-
|
|
199
197
|
if (shellpath.empty() || !path_util::file_exists(shellpath)) {
|
|
200
|
-
std::
|
|
201
|
-
why << "File not found: " <<
|
|
202
|
-
Nan::ThrowError(why.str().c_str());
|
|
198
|
+
std::wstringstream why;
|
|
199
|
+
why << "File not found: " << shellpath;
|
|
200
|
+
Nan::ThrowError(path_util::from_wstring(why.str().c_str()));
|
|
203
201
|
return;
|
|
204
202
|
}
|
|
205
203
|
|
|
@@ -223,14 +221,20 @@ static NAN_METHOD(PtyStartProcess) {
|
|
|
223
221
|
return;
|
|
224
222
|
}
|
|
225
223
|
|
|
226
|
-
|
|
227
|
-
{
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
std::string conoutPipeNameStr(outName.begin(), outName.end());
|
|
232
|
-
Nan::Set(marshal, Nan::New<v8::String>("conout").ToLocalChecked(), Nan::New<v8::String>(conoutPipeNameStr).ToLocalChecked());
|
|
224
|
+
std::string inNameStr(path_util::from_wstring(inName.c_str()));
|
|
225
|
+
if (inNameStr.empty()) {
|
|
226
|
+
Nan::ThrowError("Failed to initialize conpty conin");
|
|
227
|
+
return;
|
|
233
228
|
}
|
|
229
|
+
std::string outNameStr(path_util::from_wstring(outName.c_str()));
|
|
230
|
+
if (outNameStr.empty()) {
|
|
231
|
+
Nan::ThrowError("Failed to initialize conpty conout");
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
Nan::Set(marshal, Nan::New<v8::String>("fd").ToLocalChecked(), Nan::New<v8::Number>(-1));
|
|
236
|
+
Nan::Set(marshal, Nan::New<v8::String>("conin").ToLocalChecked(), Nan::New<v8::String>(inNameStr).ToLocalChecked());
|
|
237
|
+
Nan::Set(marshal, Nan::New<v8::String>("conout").ToLocalChecked(), Nan::New<v8::String>(outNameStr).ToLocalChecked());
|
|
234
238
|
info.GetReturnValue().Set(marshal);
|
|
235
239
|
}
|
|
236
240
|
|
|
@@ -396,8 +400,8 @@ static NAN_METHOD(PtyResize) {
|
|
|
396
400
|
}
|
|
397
401
|
|
|
398
402
|
int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust();
|
|
399
|
-
SHORT cols = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust();
|
|
400
|
-
SHORT rows = info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust();
|
|
403
|
+
SHORT cols = static_cast<SHORT>(info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust());
|
|
404
|
+
SHORT rows = static_cast<SHORT>(info[2]->Uint32Value(Nan::GetCurrentContext()).FromJust());
|
|
401
405
|
|
|
402
406
|
const pty_baton* handle = get_pty_baton(id);
|
|
403
407
|
|
|
@@ -12,7 +12,7 @@ static NAN_METHOD(ApiConsoleProcessList) {
|
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const DWORD pid = info[0]->Uint32Value(Nan::GetCurrentContext()).FromJust();
|
|
16
16
|
|
|
17
17
|
if (!FreeConsole()) {
|
|
18
18
|
Nan::ThrowError("FreeConsole failed");
|
|
@@ -21,10 +21,10 @@ static NAN_METHOD(ApiConsoleProcessList) {
|
|
|
21
21
|
Nan::ThrowError("AttachConsole failed");
|
|
22
22
|
}
|
|
23
23
|
auto processList = std::vector<DWORD>(64);
|
|
24
|
-
auto processCount = GetConsoleProcessList(&processList[0], processList.size());
|
|
24
|
+
auto processCount = GetConsoleProcessList(&processList[0], static_cast<DWORD>(processList.size()));
|
|
25
25
|
if (processList.size() < processCount) {
|
|
26
26
|
processList.resize(processCount);
|
|
27
|
-
processCount = GetConsoleProcessList(&processList[0], processList.size());
|
|
27
|
+
processCount = GetConsoleProcessList(&processList[0], static_cast<DWORD>(processList.size()));
|
|
28
28
|
}
|
|
29
29
|
FreeConsole();
|
|
30
30
|
|
package/src/win/path_util.cc
CHANGED
|
@@ -13,9 +13,28 @@ namespace path_util {
|
|
|
13
13
|
|
|
14
14
|
const wchar_t* to_wstring(const Nan::Utf8String& str) {
|
|
15
15
|
const char *bytes = *str;
|
|
16
|
-
|
|
16
|
+
int sizeOfStr = MultiByteToWideChar(CP_UTF8, 0, bytes, -1, NULL, 0);
|
|
17
|
+
if (sizeOfStr <= 0) {
|
|
18
|
+
return L"";
|
|
19
|
+
}
|
|
17
20
|
wchar_t *output = new wchar_t[sizeOfStr];
|
|
18
|
-
MultiByteToWideChar(CP_UTF8, 0, bytes, -1, output, sizeOfStr);
|
|
21
|
+
int status = MultiByteToWideChar(CP_UTF8, 0, bytes, -1, output, sizeOfStr);
|
|
22
|
+
if (status == 0) {
|
|
23
|
+
return L"";
|
|
24
|
+
}
|
|
25
|
+
return output;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const char* from_wstring(const wchar_t* wstr) {
|
|
29
|
+
int bufferSize = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
|
|
30
|
+
if (bufferSize <= 0) {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
char *output = new char[bufferSize];
|
|
34
|
+
int status = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, output, bufferSize, NULL, NULL);
|
|
35
|
+
if (status == 0) {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
19
38
|
return output;
|
|
20
39
|
}
|
|
21
40
|
|
package/src/win/path_util.h
CHANGED
package/src/win/winpty.cc
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
#include <iostream>
|
|
12
|
+
#include <map>
|
|
12
13
|
#include <nan.h>
|
|
13
14
|
#include <Shlwapi.h> // PathCombine, PathIsRelative
|
|
14
15
|
#include <sstream>
|
|
@@ -37,21 +38,25 @@ static volatile LONG ptyCounter;
|
|
|
37
38
|
* Helpers
|
|
38
39
|
*/
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
/** Keeps track of the handles created by PtyStartProcess */
|
|
42
|
+
static std::map<DWORD, HANDLE> createdHandles;
|
|
43
|
+
|
|
44
|
+
static winpty_t *get_pipe_handle(DWORD pid) {
|
|
41
45
|
for (size_t i = 0; i < ptyHandles.size(); ++i) {
|
|
42
46
|
winpty_t *ptyHandle = ptyHandles[i];
|
|
43
|
-
|
|
44
|
-
if (current ==
|
|
47
|
+
HANDLE current = winpty_agent_process(ptyHandle);
|
|
48
|
+
if (GetProcessId(current) == pid) {
|
|
45
49
|
return ptyHandle;
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
52
|
return nullptr;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
static bool remove_pipe_handle(
|
|
55
|
+
static bool remove_pipe_handle(DWORD pid) {
|
|
52
56
|
for (size_t i = 0; i < ptyHandles.size(); ++i) {
|
|
53
57
|
winpty_t *ptyHandle = ptyHandles[i];
|
|
54
|
-
|
|
58
|
+
HANDLE current = winpty_agent_process(ptyHandle);
|
|
59
|
+
if (GetProcessId(current) == pid) {
|
|
55
60
|
winpty_free(ptyHandle);
|
|
56
61
|
ptyHandles.erase(ptyHandles.begin() + i);
|
|
57
62
|
ptyHandle = nullptr;
|
|
@@ -62,11 +67,10 @@ static bool remove_pipe_handle(int handle) {
|
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
void throw_winpty_error(const char *generalMsg, winpty_error_ptr_t error_ptr) {
|
|
65
|
-
std::
|
|
70
|
+
std::wstringstream why;
|
|
66
71
|
std::wstring msg(winpty_error_msg(error_ptr));
|
|
67
|
-
|
|
68
|
-
why
|
|
69
|
-
Nan::ThrowError(why.str().c_str());
|
|
72
|
+
why << generalMsg << ": " << msg;
|
|
73
|
+
Nan::ThrowError(path_util::from_wstring(why.str().c_str()));
|
|
70
74
|
winpty_error_free(error_ptr);
|
|
71
75
|
}
|
|
72
76
|
|
|
@@ -75,13 +79,24 @@ static NAN_METHOD(PtyGetExitCode) {
|
|
|
75
79
|
|
|
76
80
|
if (info.Length() != 1 ||
|
|
77
81
|
!info[0]->IsNumber()) {
|
|
78
|
-
Nan::ThrowError("Usage: pty.getExitCode(
|
|
82
|
+
Nan::ThrowError("Usage: pty.getExitCode(pid)");
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
DWORD pid = info[0]->Uint32Value(Nan::GetCurrentContext()).FromJust();
|
|
87
|
+
HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
|
|
88
|
+
if (handle == NULL) {
|
|
89
|
+
info.GetReturnValue().Set(Nan::New<v8::Number>(-1));
|
|
79
90
|
return;
|
|
80
91
|
}
|
|
81
92
|
|
|
82
93
|
DWORD exitCode = 0;
|
|
83
|
-
GetExitCodeProcess(
|
|
94
|
+
BOOL success = GetExitCodeProcess(handle, &exitCode);
|
|
95
|
+
if (success == FALSE) {
|
|
96
|
+
exitCode = -1;
|
|
97
|
+
}
|
|
84
98
|
|
|
99
|
+
CloseHandle(handle);
|
|
85
100
|
info.GetReturnValue().Set(Nan::New<v8::Number>(exitCode));
|
|
86
101
|
}
|
|
87
102
|
|
|
@@ -94,8 +109,7 @@ static NAN_METHOD(PtyGetProcessList) {
|
|
|
94
109
|
return;
|
|
95
110
|
}
|
|
96
111
|
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
DWORD pid = info[0]->Uint32Value(Nan::GetCurrentContext()).FromJust();
|
|
99
113
|
winpty_t *pc = get_pipe_handle(pid);
|
|
100
114
|
if (pc == nullptr) {
|
|
101
115
|
info.GetReturnValue().Set(Nan::New<v8::Array>(0));
|
|
@@ -104,9 +118,13 @@ static NAN_METHOD(PtyGetProcessList) {
|
|
|
104
118
|
int processList[64];
|
|
105
119
|
const int processCount = 64;
|
|
106
120
|
int actualCount = winpty_get_console_process_list(pc, processList, processCount, nullptr);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
121
|
+
if (actualCount <= 0) {
|
|
122
|
+
info.GetReturnValue().Set(Nan::New<v8::Array>(0));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
uint32_t actualCountSize = static_cast<uint32_t>(actualCount);
|
|
126
|
+
v8::Local<v8::Array> result = Nan::New<v8::Array>(actualCountSize);
|
|
127
|
+
for (uint32_t i = 0; i < actualCountSize; i++) {
|
|
110
128
|
Nan::Set(result, i, Nan::New<v8::Number>(processList[i]));
|
|
111
129
|
}
|
|
112
130
|
info.GetReturnValue().Set(result);
|
|
@@ -127,8 +145,6 @@ static NAN_METHOD(PtyStartProcess) {
|
|
|
127
145
|
return;
|
|
128
146
|
}
|
|
129
147
|
|
|
130
|
-
std::stringstream why;
|
|
131
|
-
|
|
132
148
|
const wchar_t *filename = path_util::to_wstring(Nan::Utf8String(info[0]));
|
|
133
149
|
const wchar_t *cmdline = path_util::to_wstring(Nan::Utf8String(info[1]));
|
|
134
150
|
const wchar_t *cwd = path_util::to_wstring(Nan::Utf8String(info[3]));
|
|
@@ -157,12 +173,14 @@ static NAN_METHOD(PtyStartProcess) {
|
|
|
157
173
|
shellpath = filename;
|
|
158
174
|
}
|
|
159
175
|
|
|
160
|
-
std::string shellpath_(shellpath.begin(), shellpath.end());
|
|
161
|
-
|
|
162
176
|
if (shellpath.empty() || !path_util::file_exists(shellpath)) {
|
|
163
|
-
why
|
|
164
|
-
|
|
165
|
-
|
|
177
|
+
std::wstringstream why;
|
|
178
|
+
why << "File not found: " << shellpath;
|
|
179
|
+
Nan::ThrowError(path_util::from_wstring(why.str().c_str()));
|
|
180
|
+
delete filename;
|
|
181
|
+
delete cmdline;
|
|
182
|
+
delete cwd;
|
|
183
|
+
return;
|
|
166
184
|
}
|
|
167
185
|
|
|
168
186
|
int cols = info[4]->Int32Value(Nan::GetCurrentContext()).FromJust();
|
|
@@ -177,7 +195,10 @@ static NAN_METHOD(PtyStartProcess) {
|
|
|
177
195
|
winpty_config_t* winpty_config = winpty_config_new(0, &error_ptr);
|
|
178
196
|
if (winpty_config == nullptr) {
|
|
179
197
|
throw_winpty_error("Error creating WinPTY config", error_ptr);
|
|
180
|
-
|
|
198
|
+
delete filename;
|
|
199
|
+
delete cmdline;
|
|
200
|
+
delete cwd;
|
|
201
|
+
return;
|
|
181
202
|
}
|
|
182
203
|
winpty_error_free(error_ptr);
|
|
183
204
|
|
|
@@ -189,18 +210,22 @@ static NAN_METHOD(PtyStartProcess) {
|
|
|
189
210
|
winpty_config_free(winpty_config);
|
|
190
211
|
if (pc == nullptr) {
|
|
191
212
|
throw_winpty_error("Error launching WinPTY agent", error_ptr);
|
|
192
|
-
|
|
213
|
+
delete filename;
|
|
214
|
+
delete cmdline;
|
|
215
|
+
delete cwd;
|
|
216
|
+
return;
|
|
193
217
|
}
|
|
194
218
|
winpty_error_free(error_ptr);
|
|
195
219
|
|
|
196
|
-
// Save pty struct for later use
|
|
197
|
-
ptyHandles.insert(ptyHandles.end(), pc);
|
|
198
|
-
|
|
199
220
|
// Create winpty spawn config
|
|
200
221
|
winpty_spawn_config_t* config = winpty_spawn_config_new(WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN, shellpath.c_str(), cmdline, cwd, env.c_str(), &error_ptr);
|
|
201
222
|
if (config == nullptr) {
|
|
202
223
|
throw_winpty_error("Error creating WinPTY spawn config", error_ptr);
|
|
203
|
-
|
|
224
|
+
winpty_free(pc);
|
|
225
|
+
delete filename;
|
|
226
|
+
delete cmdline;
|
|
227
|
+
delete cwd;
|
|
228
|
+
return;
|
|
204
229
|
}
|
|
205
230
|
winpty_error_free(error_ptr);
|
|
206
231
|
|
|
@@ -210,32 +235,68 @@ static NAN_METHOD(PtyStartProcess) {
|
|
|
210
235
|
winpty_spawn_config_free(config);
|
|
211
236
|
if (!spawnSuccess) {
|
|
212
237
|
throw_winpty_error("Unable to start terminal process", error_ptr);
|
|
213
|
-
|
|
238
|
+
if (handle) {
|
|
239
|
+
CloseHandle(handle);
|
|
240
|
+
}
|
|
241
|
+
winpty_free(pc);
|
|
242
|
+
delete filename;
|
|
243
|
+
delete cmdline;
|
|
244
|
+
delete cwd;
|
|
245
|
+
return;
|
|
214
246
|
}
|
|
215
247
|
winpty_error_free(error_ptr);
|
|
216
248
|
|
|
217
|
-
|
|
249
|
+
LPCWSTR coninPipeName = winpty_conin_name(pc);
|
|
250
|
+
std::string coninPipeNameStr(path_util::from_wstring(coninPipeName));
|
|
251
|
+
if (coninPipeNameStr.empty()) {
|
|
252
|
+
Nan::ThrowError("Failed to initialize winpty conin");
|
|
253
|
+
CloseHandle(handle);
|
|
254
|
+
winpty_free(pc);
|
|
255
|
+
delete filename;
|
|
256
|
+
delete cmdline;
|
|
257
|
+
delete cwd;
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
LPCWSTR conoutPipeName = winpty_conout_name(pc);
|
|
262
|
+
std::string conoutPipeNameStr(path_util::from_wstring(conoutPipeName));
|
|
263
|
+
if (conoutPipeNameStr.empty()) {
|
|
264
|
+
Nan::ThrowError("Failed to initialize winpty conout");
|
|
265
|
+
CloseHandle(handle);
|
|
266
|
+
winpty_free(pc);
|
|
267
|
+
delete filename;
|
|
268
|
+
delete cmdline;
|
|
269
|
+
delete cwd;
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
DWORD innerPid = GetProcessId(handle);
|
|
274
|
+
if (createdHandles[innerPid]) {
|
|
275
|
+
std::stringstream why;
|
|
276
|
+
why << "There is already a process with innerPid " << innerPid;
|
|
277
|
+
Nan::ThrowError(why.str().c_str());
|
|
278
|
+
CloseHandle(handle);
|
|
279
|
+
winpty_free(pc);
|
|
280
|
+
delete filename;
|
|
281
|
+
delete cmdline;
|
|
282
|
+
delete cwd;
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
createdHandles[innerPid] = handle;
|
|
286
|
+
|
|
287
|
+
// Save pty struct for later use
|
|
288
|
+
ptyHandles.push_back(pc);
|
|
289
|
+
|
|
218
290
|
v8::Local<v8::Object> marshal = Nan::New<v8::Object>();
|
|
219
|
-
|
|
220
|
-
Nan::Set(marshal, Nan::New<v8::String>("
|
|
221
|
-
Nan::Set(marshal, Nan::New<v8::String>("pid").ToLocalChecked(), Nan::New<v8::Number>((
|
|
291
|
+
DWORD pid = GetProcessId(winpty_agent_process(pc));
|
|
292
|
+
Nan::Set(marshal, Nan::New<v8::String>("innerPid").ToLocalChecked(), Nan::New<v8::Number>(static_cast<double>(innerPid)));
|
|
293
|
+
Nan::Set(marshal, Nan::New<v8::String>("pid").ToLocalChecked(), Nan::New<v8::Number>(static_cast<double>(pid)));
|
|
222
294
|
Nan::Set(marshal, Nan::New<v8::String>("pty").ToLocalChecked(), Nan::New<v8::Number>(InterlockedIncrement(&ptyCounter)));
|
|
223
295
|
Nan::Set(marshal, Nan::New<v8::String>("fd").ToLocalChecked(), Nan::New<v8::Number>(-1));
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
std::wstring coninPipeNameWStr(coninPipeName);
|
|
227
|
-
std::string coninPipeNameStr(coninPipeNameWStr.begin(), coninPipeNameWStr.end());
|
|
228
|
-
Nan::Set(marshal, Nan::New<v8::String>("conin").ToLocalChecked(), Nan::New<v8::String>(coninPipeNameStr).ToLocalChecked());
|
|
229
|
-
LPCWSTR conoutPipeName = winpty_conout_name(pc);
|
|
230
|
-
std::wstring conoutPipeNameWStr(conoutPipeName);
|
|
231
|
-
std::string conoutPipeNameStr(conoutPipeNameWStr.begin(), conoutPipeNameWStr.end());
|
|
232
|
-
Nan::Set(marshal, Nan::New<v8::String>("conout").ToLocalChecked(), Nan::New<v8::String>(conoutPipeNameStr).ToLocalChecked());
|
|
233
|
-
}
|
|
296
|
+
Nan::Set(marshal, Nan::New<v8::String>("conin").ToLocalChecked(), Nan::New<v8::String>(coninPipeNameStr).ToLocalChecked());
|
|
297
|
+
Nan::Set(marshal, Nan::New<v8::String>("conout").ToLocalChecked(), Nan::New<v8::String>(conoutPipeNameStr).ToLocalChecked());
|
|
234
298
|
info.GetReturnValue().Set(marshal);
|
|
235
299
|
|
|
236
|
-
goto cleanup;
|
|
237
|
-
|
|
238
|
-
cleanup:
|
|
239
300
|
delete filename;
|
|
240
301
|
delete cmdline;
|
|
241
302
|
delete cwd;
|
|
@@ -252,11 +313,11 @@ static NAN_METHOD(PtyResize) {
|
|
|
252
313
|
return;
|
|
253
314
|
}
|
|
254
315
|
|
|
255
|
-
|
|
316
|
+
DWORD pid = info[0]->Uint32Value(Nan::GetCurrentContext()).FromJust();
|
|
256
317
|
int cols = info[1]->Int32Value(Nan::GetCurrentContext()).FromJust();
|
|
257
318
|
int rows = info[2]->Int32Value(Nan::GetCurrentContext()).FromJust();
|
|
258
319
|
|
|
259
|
-
winpty_t *pc = get_pipe_handle(
|
|
320
|
+
winpty_t *pc = get_pipe_handle(pid);
|
|
260
321
|
|
|
261
322
|
if (pc == nullptr) {
|
|
262
323
|
Nan::ThrowError("The pty doesn't appear to exist");
|
|
@@ -277,20 +338,23 @@ static NAN_METHOD(PtyKill) {
|
|
|
277
338
|
if (info.Length() != 2 ||
|
|
278
339
|
!info[0]->IsNumber() ||
|
|
279
340
|
!info[1]->IsNumber()) {
|
|
280
|
-
Nan::ThrowError("Usage: pty.kill(pid,
|
|
341
|
+
Nan::ThrowError("Usage: pty.kill(pid, innerPid)");
|
|
281
342
|
return;
|
|
282
343
|
}
|
|
283
344
|
|
|
284
|
-
|
|
285
|
-
|
|
345
|
+
DWORD pid = info[0]->Uint32Value(Nan::GetCurrentContext()).FromJust();
|
|
346
|
+
DWORD innerPid = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust();
|
|
286
347
|
|
|
287
|
-
winpty_t *pc = get_pipe_handle(
|
|
348
|
+
winpty_t *pc = get_pipe_handle(pid);
|
|
288
349
|
if (pc == nullptr) {
|
|
289
350
|
Nan::ThrowError("Pty seems to have been killed already");
|
|
290
351
|
return;
|
|
291
352
|
}
|
|
292
353
|
|
|
293
|
-
assert(remove_pipe_handle(
|
|
354
|
+
assert(remove_pipe_handle(pid));
|
|
355
|
+
|
|
356
|
+
HANDLE innerPidHandle = createdHandles[innerPid];
|
|
357
|
+
createdHandles.erase(innerPid);
|
|
294
358
|
CloseHandle(innerPidHandle);
|
|
295
359
|
|
|
296
360
|
return info.GetReturnValue().SetUndefined();
|
package/src/windowsPtyAgent.ts
CHANGED
|
@@ -31,7 +31,6 @@ export class WindowsPtyAgent {
|
|
|
31
31
|
private _outSocket: Socket;
|
|
32
32
|
private _pid: number = 0;
|
|
33
33
|
private _innerPid: number = 0;
|
|
34
|
-
private _innerPidHandle: number = 0;
|
|
35
34
|
private _closeTimeout: NodeJS.Timer | undefined;
|
|
36
35
|
private _exitCode: number | undefined;
|
|
37
36
|
private _conoutSocketWorker: ConoutConnection;
|
|
@@ -105,7 +104,6 @@ export class WindowsPtyAgent {
|
|
|
105
104
|
term = (this._ptyNative as IWinptyNative).startProcess(file, commandLine, env, cwd, cols, rows, debug);
|
|
106
105
|
this._pid = (term as IWinptyProcess).pid;
|
|
107
106
|
this._innerPid = (term as IWinptyProcess).innerPid;
|
|
108
|
-
this._innerPidHandle = (term as IWinptyProcess).innerPidHandle;
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
// Not available on windows.
|
|
@@ -174,14 +172,14 @@ export class WindowsPtyAgent {
|
|
|
174
172
|
(this._ptyNative as IConptyNative).kill(this._pty);
|
|
175
173
|
});
|
|
176
174
|
} else {
|
|
177
|
-
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
// dropped, we want to immediately kill the entire console process list.
|
|
175
|
+
// Because pty.kill closes the handle, it will kill most processes by itself.
|
|
176
|
+
// Process IDs can be reused as soon as all handles to them are
|
|
177
|
+
// dropped, so we want to immediately kill the entire console process list.
|
|
181
178
|
// If we do not force kill all processes here, node servers in particular
|
|
182
179
|
// seem to become detached and remain running (see
|
|
183
180
|
// Microsoft/vscode#26807).
|
|
184
181
|
const processList: number[] = (this._ptyNative as IWinptyNative).getProcessList(this._pid);
|
|
182
|
+
(this._ptyNative as IWinptyNative).kill(this._pid, this._innerPid);
|
|
185
183
|
processList.forEach(pid => {
|
|
186
184
|
try {
|
|
187
185
|
process.kill(pid);
|
|
@@ -212,7 +210,8 @@ export class WindowsPtyAgent {
|
|
|
212
210
|
if (this._useConpty) {
|
|
213
211
|
return this._exitCode;
|
|
214
212
|
}
|
|
215
|
-
|
|
213
|
+
const winptyExitCode = (this._ptyNative as IWinptyNative).getExitCode(this._innerPid);
|
|
214
|
+
return winptyExitCode === -1 ? undefined : winptyExitCode;
|
|
216
215
|
}
|
|
217
216
|
|
|
218
217
|
private _getWindowsBuildNumber(): number {
|
|
@@ -88,125 +88,127 @@ function pollForProcessTreeSize(pid: number, size: number, intervalMs: number =
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
if (process.platform === 'win32') {
|
|
91
|
-
|
|
92
|
-
describe(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// Add done call to deferred function queue to ensure the kill call has completed
|
|
97
|
-
(<any>term)._defer(done);
|
|
98
|
-
});
|
|
99
|
-
it('should kill the process tree', function (done: Mocha.Done): void {
|
|
100
|
-
this.timeout(5000);
|
|
101
|
-
const term = new WindowsTerminal('cmd.exe', [], {});
|
|
102
|
-
// Start sub-processes
|
|
103
|
-
term.write('powershell.exe\r');
|
|
104
|
-
term.write('notepad.exe\r');
|
|
105
|
-
term.write('node.exe\r');
|
|
106
|
-
pollForProcessTreeSize(term.pid, 4, 500, 5000).then(list => {
|
|
107
|
-
assert.strictEqual(list[0].name.toLowerCase(), 'cmd.exe');
|
|
108
|
-
assert.strictEqual(list[1].name.toLowerCase(), 'powershell.exe');
|
|
109
|
-
assert.strictEqual(list[2].name.toLowerCase(), 'notepad.exe');
|
|
110
|
-
assert.strictEqual(list[3].name.toLowerCase(), 'node.exe');
|
|
91
|
+
[true, false].forEach((useConpty) => {
|
|
92
|
+
describe(`WindowsTerminal (useConpty = ${useConpty})`, () => {
|
|
93
|
+
describe('kill', () => {
|
|
94
|
+
it('should not crash parent process', (done) => {
|
|
95
|
+
const term = new WindowsTerminal('cmd.exe', [], { useConpty });
|
|
111
96
|
term.kill();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
97
|
+
// Add done call to deferred function queue to ensure the kill call has completed
|
|
98
|
+
(<any>term)._defer(done);
|
|
99
|
+
});
|
|
100
|
+
it('should kill the process tree', function (done: Mocha.Done): void {
|
|
101
|
+
this.timeout(5000);
|
|
102
|
+
const term = new WindowsTerminal('cmd.exe', [], { useConpty });
|
|
103
|
+
// Start sub-processes
|
|
104
|
+
term.write('powershell.exe\r');
|
|
105
|
+
term.write('notepad.exe\r');
|
|
106
|
+
term.write('node.exe\r');
|
|
107
|
+
pollForProcessTreeSize(term.pid, 4, 500, 5000).then(list => {
|
|
108
|
+
assert.strictEqual(list[0].name.toLowerCase(), 'cmd.exe');
|
|
109
|
+
assert.strictEqual(list[1].name.toLowerCase(), 'powershell.exe');
|
|
110
|
+
assert.strictEqual(list[2].name.toLowerCase(), 'notepad.exe');
|
|
111
|
+
assert.strictEqual(list[3].name.toLowerCase(), 'node.exe');
|
|
112
|
+
term.kill();
|
|
113
|
+
const desiredState: IProcessState = {};
|
|
114
|
+
desiredState[list[0].pid] = false;
|
|
115
|
+
desiredState[list[1].pid] = false;
|
|
116
|
+
desiredState[list[2].pid] = true;
|
|
117
|
+
desiredState[list[3].pid] = false;
|
|
118
|
+
pollForProcessState(desiredState).then(() => {
|
|
119
|
+
// Kill notepad before done
|
|
120
|
+
process.kill(list[2].pid);
|
|
121
|
+
done();
|
|
122
|
+
});
|
|
121
123
|
});
|
|
122
124
|
});
|
|
123
125
|
});
|
|
124
|
-
});
|
|
125
126
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
127
|
+
describe('resize', () => {
|
|
128
|
+
it('should throw a non-native exception when resizing an invalid value', () => {
|
|
129
|
+
const term = new WindowsTerminal('cmd.exe', [], { useConpty });
|
|
130
|
+
assert.throws(() => term.resize(-1, -1));
|
|
131
|
+
assert.throws(() => term.resize(0, 0));
|
|
132
|
+
assert.doesNotThrow(() => term.resize(1, 1));
|
|
133
|
+
});
|
|
134
|
+
it('should throw a non-native exception when resizing a killed terminal', (done) => {
|
|
135
|
+
const term = new WindowsTerminal('cmd.exe', [], { useConpty });
|
|
136
|
+
(<any>term)._defer(() => {
|
|
137
|
+
term.on('exit', () => {
|
|
138
|
+
assert.throws(() => term.resize(1, 1));
|
|
139
|
+
done();
|
|
140
|
+
});
|
|
141
|
+
term.destroy();
|
|
139
142
|
});
|
|
140
|
-
term.destroy();
|
|
141
143
|
});
|
|
142
144
|
});
|
|
143
|
-
});
|
|
144
145
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
describe('Args as CommandLine', () => {
|
|
147
|
+
it('should not fail running a file containing a space in the path', (done) => {
|
|
148
|
+
const spaceFolder = path.resolve(__dirname, '..', 'fixtures', 'space folder');
|
|
149
|
+
if (!fs.existsSync(spaceFolder)) {
|
|
150
|
+
fs.mkdirSync(spaceFolder);
|
|
151
|
+
}
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const cmdCopiedPath = path.resolve(spaceFolder, 'cmd.exe');
|
|
154
|
+
const data = fs.readFileSync(`${process.env.windir}\\System32\\cmd.exe`);
|
|
155
|
+
fs.writeFileSync(cmdCopiedPath, data);
|
|
155
156
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
157
|
+
if (!fs.existsSync(cmdCopiedPath)) {
|
|
158
|
+
// Skip test if git bash isn't installed
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const term = new WindowsTerminal(cmdCopiedPath, '/c echo "hello world"', { useConpty });
|
|
162
|
+
let result = '';
|
|
163
|
+
term.on('data', (data) => {
|
|
164
|
+
result += data;
|
|
165
|
+
});
|
|
166
|
+
term.on('exit', () => {
|
|
167
|
+
assert.ok(result.indexOf('hello world') >= 1);
|
|
168
|
+
done();
|
|
169
|
+
});
|
|
168
170
|
});
|
|
169
171
|
});
|
|
170
|
-
});
|
|
171
172
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
173
|
+
describe('env', () => {
|
|
174
|
+
it('should set environment variables of the shell', (done) => {
|
|
175
|
+
const term = new WindowsTerminal('cmd.exe', '/C echo %FOO%', { env: { FOO: 'BAR' }});
|
|
176
|
+
let result = '';
|
|
177
|
+
term.on('data', (data) => {
|
|
178
|
+
result += data;
|
|
179
|
+
});
|
|
180
|
+
term.on('exit', () => {
|
|
181
|
+
assert.ok(result.indexOf('BAR') >= 0);
|
|
182
|
+
done();
|
|
183
|
+
});
|
|
182
184
|
});
|
|
183
185
|
});
|
|
184
|
-
});
|
|
185
186
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
187
|
+
describe('On close', () => {
|
|
188
|
+
it('should return process zero exit codes', (done) => {
|
|
189
|
+
const term = new WindowsTerminal('cmd.exe', '/C exit', { useConpty });
|
|
190
|
+
term.on('exit', (code) => {
|
|
191
|
+
assert.strictEqual(code, 0);
|
|
192
|
+
done();
|
|
193
|
+
});
|
|
192
194
|
});
|
|
193
|
-
});
|
|
194
195
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
it('should return process non-zero exit codes', (done) => {
|
|
197
|
+
const term = new WindowsTerminal('cmd.exe', '/C exit 2', { useConpty });
|
|
198
|
+
term.on('exit', (code) => {
|
|
199
|
+
assert.strictEqual(code, 2);
|
|
200
|
+
done();
|
|
201
|
+
});
|
|
200
202
|
});
|
|
201
203
|
});
|
|
202
|
-
});
|
|
203
204
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
205
|
+
describe('Write', () => {
|
|
206
|
+
it('should accept input', (done) => {
|
|
207
|
+
const term = new WindowsTerminal('cmd.exe', '', { useConpty });
|
|
208
|
+
term.write('exit\r');
|
|
209
|
+
term.on('exit', () => {
|
|
210
|
+
done();
|
|
211
|
+
});
|
|
210
212
|
});
|
|
211
213
|
});
|
|
212
214
|
});
|