help icon indicating copy to clipboard operation
help copied to clipboard

`childProcess.stdin.write()` is not working

Open yxshv opened this issue 1 year ago • 3 comments

Details

So I am trying to communicate with the tsserver and am trying to write to the tsserver stdin

import { spawn } from 'child_process';

const { stdin: input, stdout: output }  = spawn('./node_modules/.bin/tsserver', []);

input.setDefaultEncoding('utf-8')

setTimeout(start, 5000)

output.pipe(process.stdout);

const textDocument = {
  uri: 'file:///Users/balkrishnaverma/Documents/yash/testum/src/index.ts',
  languageId: 'typescript',
  version: 2,
  text: `type JustATest  = {
  a: string,
  b: number
}
const abcd: Jus
`
};

async function start() {
  input.cork()
  input.write(JSON.stringify({
    seq: 0,
    type: "request",
    command: "open",
    arguments: {
      file: "/Users/balkrishnaverma/Documents/yash/testum/src/index.ts",
      fileContent: textDocument.text,
      projectRootPath: "/Users/balkrishnaverma/Documents/yash/testum",
    }
  }))
  input.uncork()
}

but its not actually writing for some reason? when i pipe process.stdin.pipe(input) and type json from my terminal it works?

Node.js version

{
  node: '20.10.0',
  acorn: '8.10.0',
  ada: '2.7.2',
  ares: '1.20.1',
  base64: '0.5.0',
  brotli: '1.0.9',
  cjs_module_lexer: '1.2.2',
  cldr: '43.1',
  icu: '73.2',
  llhttp: '8.1.1',
  modules: '115',
  napi: '9',
  nghttp2: '1.57.0',
  nghttp3: '0.7.0',
  ngtcp2: '0.8.1',
  openssl: '3.0.12+quic',
  simdutf: '3.2.18',
  tz: '2023c',
  undici: '5.26.4',
  unicode: '15.0',
  uv: '1.46.0',
  uvwasi: '0.0.19',
  v8: '11.3.244.8-node.25',
  zlib: '1.2.13.1-motley'
}

Example code

No response

Operating system

MacOS

output of uname-a

Darwin Balkrishnas-MacBook-Air.local 21.6.0 Darwin Kernel Version 21.6.0: Thu Jul  6 22:18:26 PDT 2023; root:xnu-8020.240.18.702.13~1/RELEASE_X86_64 x86_64

Module and version

Not applicable.

yxshv avatar Jan 02 '24 16:01 yxshv

Can you try adding a \n at the end of write?

preveen-stack avatar Jan 07 '24 04:01 preveen-stack

Can you try adding a \n at the end of write?

I had tried that doesn't work

yxshv avatar Jan 07 '24 12:01 yxshv

Is this issue still occuring? If not, feel free to self-close.

avivkeller avatar Jul 01 '24 23:07 avivkeller

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar Dec 29 '24 01:12 github-actions[bot]

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar Jan 29 '25 01:01 github-actions[bot]