Skip to content

Commit dbe1f70

Browse files
committed
fix: terminal shellCommand execution on Windows
Wait for shell prompt before writing command instead of firing immediately after PTY spawn. Use \r (carriage return) instead of \n for command submission, matching what xterm.js sends for Enter.
1 parent abff220 commit dbe1f70

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/extensionsIntegrated/Terminal/TerminalInstance.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ define(function (require, exports, module) {
108108
this._webglAddon = null;
109109
this._lastDpr = null;
110110

111+
// Promise that resolves when the shell sends its first output (prompt ready)
112+
this._firstDataResolve = null;
113+
this.firstDataReceived = new Promise(function (resolve) {
114+
this._firstDataResolve = resolve;
115+
}.bind(this));
116+
111117
// Bound event handlers for cleanup
112118
this._onTerminalData = this._onTerminalData.bind(this);
113119
this._onTerminalExit = this._onTerminalExit.bind(this);
@@ -217,6 +223,10 @@ define(function (require, exports, module) {
217223
TerminalInstance.prototype._onTerminalData = function (_event, eventData) {
218224
if (eventData.id === this.id && this.terminal) {
219225
this.terminal.write(eventData.data);
226+
if (this._firstDataResolve) {
227+
this._firstDataResolve();
228+
this._firstDataResolve = null;
229+
}
220230
}
221231
};
222232

src/extensionsIntegrated/Terminal/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,11 @@ define(function (require, exports, module) {
557557
await _createNewTerminal();
558558
const active = _getActiveTerminal();
559559
if (active && active.isAlive) {
560+
// Wait for the shell to output its prompt before sending the command.
561+
await active.firstDataReceived;
560562
nodeConnector.execPeer("writeTerminal", {
561563
id: active.id,
562-
data: options.shellCommand + "\n"
564+
data: options.shellCommand + "\r"
563565
});
564566
}
565567
return;

0 commit comments

Comments
 (0)