如何使用Node JS执行Windows Shell命令(Cmd.exe) [英] How To Execute Windows Shell Commands (Cmd.exe) with Node JS
问题描述
我想
C:\> ACommandThatGetsData> save.txt
但是我不想在控制台中解析和保存数据,我想使用Node.JS
But instead of parsing and saving the data in the console, I would like to do the above command with Node.JS
如何使用Node.JS执行shell命令?
How to I execute a shell command with Node.JS?
推荐答案
<<>使用 process.execPath()
:
process.execPath('/path/to/executable');
我应该更好地阅读文档。
I should have read the documentations better.
有一个子进程模块,允许执行子进程。您需要 child_process.exec
, child_process.execFile
或 child_process.spawn
。所有这些都是类似的使用,但每个都有自己的优势。其中哪些使用取决于您的需要。
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.
这篇关于如何使用Node JS执行Windows Shell命令(Cmd.exe)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!