How To Execute Windows Shell Commands (Cmd.exe) with Node JS

前端 未结 2 477
猫巷女王i
猫巷女王i 2021-01-01 18:47

I would like to

C:\\>ACommandThatGetsData > save.txt

But instead of parsing and saving the data in the console, I would like to do th

2条回答
  •  有刺的猬
    2021-01-01 19:28

    Use process.execPath():

    process.execPath('/path/to/executable');
    

    Update

    I should have read the documentations better.

    There is a Child Process Module which allows to execute a child process. You will need either child_process.exec, child_process.execFile or child_process.spawn. All of these are similar in use, but each has its own advantages. Which of them to use depends on your needs.

提交回复
热议问题