lib/pty_win.js
function Agent(file, args, env, cwd, cols, rows, debug) {
  var self = this;

  // Increment the number of pipes created.
  pipeIncr++;

  // Unique identifier per pipe created.
  var timestamp = Date.now();

  // The data pipe is the direct connection to the forked terminal.
  this.dataPipe = '\\\\.\\pipe\\winpty-data-' + pipeIncr + '' + timestamp;

  // Dummy socket for awaiting `ready` event.
  this.ptySocket = new net.Socket();

  // Create terminal pipe IPC channel and forward
  // to a local unix socket.
  this.ptyDataPipe = net.createServer(function (socket) {

    // Default socket encoding.
    socket.setEncoding('utf8');

    // Pause until `ready` event is emitted.
    socket.pause();

    // Sanitize input variable.
    file = file;
    args = args.join(' ');
    cwd = path.resolve(cwd);

    // Start terminal session.
    pty.startProcess(self.pid, file, args, env, cwd);

    // Emit ready event.
    self.ptySocket.emit('ready_datapipe', socket);

  }).listen(this.dataPipe);

  // Open pty session.
  var term = pty.open(self.dataPipe, cols, rows, debug);

  // Terminal pid.
  this.pid = term.pid;

  // Not available on windows.
  this.fd = term.fd;

  // Generated incremental number that has no real purpose besides
  // using it as a terminal id.
  this.pty = term.pty;
}
function Agent(file, args, env, cwd, cols, rows, debug) {
  var self = this;

  // Increment the number of pipes created.
  pipeIncr++;

  // Unique identifier per pipe created.
  var timestamp = Date.now();

  // The data pipe is the direct connection to the forked terminal.
  this.dataPipe = '\\\\.\\pipe\\winpty-data-' + pipeIncr + '' + timestamp;

  // Dummy socket for awaiting `ready` event.
  this.ptySocket = new net.Socket();

  // Create terminal pipe IPC channel and forward
  // to a local unix socket.
  this.ptyDataPipe = net.createServer(function (socket) {

    // Default socket encoding.
    socket.setEncoding('utf8');

    // Pause until `ready` event is emitted.
    socket.pause();

    // Sanitize input variable.
    file = file;
    args = args.join(' ');
    cwd = path.resolve(cwd);

    // Start terminal session.
    pty.startProcess(self.pid, file, args, env, cwd);

    // Emit ready event.
    self.ptySocket.emit('ready_datapipe', socket);

  }).listen(this.dataPipe);

  // Open pty session.
  var term = pty.open(self.dataPipe, cols, rows, debug);

  // Terminal pid.
  this.pid = term.pid;

  // Not available on windows.
  this.fd = term.fd;

  // Generated incremental number that has no real purpose besides
  // using it as a terminal id.
  this.pty = term.pty;
}
function Agent ( file , args , env , cwd , cols , rows , debug ) { var self = this ; // Increment the number of pipes created. pipeIncr ++ ; // Unique identifier per pipe created. var timestamp = Date . now ( ) ; // The data pipe is the direct connection to the forked terminal. this . dataPipe = '\\\\.\\pipe\\winpty-data-' + pipeIncr + '' + timestamp ; // Dummy socket for awaiting `ready` event. this . ptySocket = new net . Socket ( ) ; // Create terminal pipe IPC channel and forward // to a local unix socket. this . ptyDataPipe = net . createServer ( function ( socket ) { // Default socket encoding. socket . setEncoding ( 'utf8' ) ; // Pause until `ready` event is emitted. socket . pause ( ) ; // Sanitize input variable. file = file ; args = args . join ( ' ' ) ; cwd = path . resolve ( cwd ) ; // Start terminal session. pty . startProcess ( self . pid , file , args , env , cwd ) ; // Emit ready event. self . ptySocket . emit ( 'ready_datapipe' , socket ) ; } ) . listen ( this . dataPipe ) ; // Open pty session. var term = pty . open ( self . dataPipe , cols , rows , debug ) ; // Terminal pid. this . pid = term . pid ; // Not available on windows. this . fd = term . fd ; // Generated incremental number that has no real purpose besides // using it as a terminal id. this . pty = term . pty ; }
Agent. Internal class.

Everytime a new pseudo terminal is created it is contained
within agent.exe. When this process is started there are two
available named pipes (control and data socket).
Agent . Internal class .