Skip to content

Commit

Permalink
Merge pull request #460 from Eugeny/fixed-node14-winpty-conin
Browse files Browse the repository at this point in the history
Explicitly open winpty conin pipe in write-only mode - fixes #457
  • Loading branch information
Tyriar authored Feb 16, 2021
2 parents b532aef + d26cba1 commit 87990b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
matrix:
node_12_x:
node_version: 12.x
node_14_x:
node_version: 14.x
steps:
- task: NodeTool@0
inputs:
Expand All @@ -33,6 +35,8 @@ jobs:
matrix:
node_12_x:
node_version: 12.x
node_14_x:
node_version: 14.x
steps:
- task: NodeTool@0
inputs:
Expand All @@ -55,6 +59,8 @@ jobs:
matrix:
node_12_x:
node_version: 12.x
node_14_x:
node_version: 14.x
steps:
- task: NodeTool@0
inputs:
Expand Down
9 changes: 7 additions & 2 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 @@ -126,9 +127,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);

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 87990b2

Please sign in to comment.