Skip to content

Support auto-answering the batch "Terminate batch job (Y/N)?" question #133524

@Tyriar

Description

@Tyriar

When you hit ^C during batch scripts they will ask this "Terminate batch job (Y/N)?" question which is super annoying and often the process that the batch script was running has already been killed anyway.

Clink works around this by allowing configuring to auto answer the question and it's really nice. I put together a little prototype and it feels great:
recording (86)

The above was done by translating the terminal line to a string whenever process data comes in and checking if it contains that text. We would want to look into faster alternatives to that and to also ensure we don't answer twice for the same line (just in case):

	private _onProcessData(ev: IProcessDataEvent): void {
		const messageId = ++this._latestXtermWriteData;
		if (ev.trackCommit) {
			ev.writePromise = new Promise<void>(r => {
				this._xterm?.write(ev.data, () => {
					this._latestXtermParseData = messageId;
					this._processManager.acknowledgeDataEvent(ev.data.length);
					const line = this._xterm?.buffer.active.getLine(this._xterm.buffer.active.baseY + this._xterm.buffer.active.cursorY)?.translateToString(true);
					if (line && line.indexOf('Terminate batch job (Y/N)') >= 0) {
						this._processManager.write('Y\r').then(() => {
							this._onDidInputData.fire(this);
						});
					}
					r();
				});
			});
		} else {
			this._xterm?.write(ev.data, () => {
				this._latestXtermParseData = messageId;
				this._processManager.acknowledgeDataEvent(ev.data.length);
				const line = this._xterm?.buffer.active.getLine(this._xterm.buffer.active.baseY + this._xterm.buffer.active.cursorY)?.translateToString(true);
				if (line && line.indexOf('Terminate batch job (Y/N)') >= 0) {
					this._processManager.write('Y\r').then(() => {
						this._onDidInputData.fire(this);
					});
				}
			});
		}
	}

Metadata

Metadata

Assignees

Labels

feature-requestRequest for new features or functionalityinsiders-releasedPatch has been released in VS Code Insiderson-release-notesIssue/pull request mentioned in release noteson-testplanterminalGeneral terminal issues that don't fall under another labelwindowsVS Code on Windows issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions