Skip to content

Commit

Permalink
explicitly open winpty conin pipe in write-only mode - fixes microsof…
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Feb 13, 2021
1 parent 24674fd commit 2855b2e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/windowsPtyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) 2018, Microsoft Corporation (MIT License).
*/

import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { Socket } from 'net';
Expand Down Expand Up @@ -122,10 +123,13 @@ export class WindowsPtyAgent {
this._outSocket.emit('ready_datapipe');
});

this._inSocket = new Socket();
const inSocketFD = fs.openSync(term.conin, 'w');
this._inSocket = new Socket({
fd: inSocketFD,
readable: false,
writable: true
});
this._inSocket.setEncoding('utf8');
this._inSocket.connect(term.conin);
// TODO: Wait for ready event?

if (this._useConpty) {
const connect = (this._ptyNative as IConptyNative).connect(this._pty, commandLine, cwd, env, c => this._$onProcessExit(c));
Expand Down
10 changes: 10 additions & 0 deletions src/windowsTerminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,15 @@ if (process.platform === 'win32') {
});
});
});

describe('winpty', () => {
it('should accept input', (done) => {
const term = new WindowsTerminal('cmd.exe', '', { useConpty: false });
term.write('exit\r');
term.on('exit', () => {
done();
});
});
});
});
}

0 comments on commit 2855b2e

Please sign in to comment.