| 84 | }; |
| 85 | |
| 86 | setUpSocketForSingleUse(sock: net.Socket, key: string) { |
| 87 | sock.on("connect", function () { |
| 88 | const inputBuffers: Buffer[] = []; |
| 89 | process.stdin.on("data", buffer => inputBuffers.push(buffer)); |
| 90 | process.stdin.on("end", () => { |
| 91 | sock.write(JSON.stringify({ |
| 92 | evaluateAndExit: { |
| 93 | // Make sure the entire command is written as a string within a |
| 94 | // JSON object, so that the server can easily tell when it has |
| 95 | // received the whole command. |
| 96 | command: Buffer.concat(inputBuffers).toString("utf8") |
| 97 | }, |
| 98 | terminal: false, |
| 99 | key: key |
| 100 | }) + "\n"); |
| 101 | }); |
| 102 | }); |
| 103 | |
| 104 | const outputBuffers: Buffer[] = []; |
| 105 | sock.on("data", buffer => outputBuffers.push(buffer)); |
| 106 | sock.on("close", function () { |
| 107 | const output = JSON.parse(Buffer.concat(outputBuffers)); |
| 108 | if (output.error) { |
| 109 | console.error(output.error); |
| 110 | process.exit(output.code); |
| 111 | } else { |
| 112 | process.stdout.write(JSON.stringify(output.result) + "\n"); |
| 113 | process.exit(0); |
| 114 | } |
| 115 | }); |
| 116 | }; |
| 117 | |
| 118 | setUpSocket(sock: net.Socket, key: string) { |
| 119 | if (!process.stdin.isTTY) { |