node.js can be used not only to write scripts for web pages, but also to run Linux commands on the server. The advantage of running the Linux node.js command line command is that it is fast and efficient. This article will introduce the method of executing linux commands using the node.js command line.
var sys = require (& lsquo; sys & rsquo;)
var exec = require (& lsquo; child_process & rsquo;) exec;.
//executes `pwd`
exec(“pwd”, function (error, stdout, stderr) {
sys.print(‘stdout: ’ + stdout);
sys. Print(‘stderr: ’ + stderr);
if (error !== null) {
console.log(‘exec error: ’ + error);
}
});
There is a need to execute shell commands from the front-end operations server
Creating a process.js file
Need to execute shell commands from the front-end operation server
Create a process.js file
var process = require(‘child_process’);
//Direct command
export.createDir = function (){process.exec(‘D: && cd testweb && md mydir’,
function Error, stdout, stderr) {
if (error !== null) {
console.log(‘exec error: ’ + error);
}
});
}
//Invoke Execution File
exports.openApp = function(){
process.execFile (‘D:/testweb/aaa.bat’,null,{cwd:‘D:/’},
function (error,stdout,stderr) {
if ( Error ! == null) {
console.log(‘exec error: ’ + error);
}
});
}< Br>
The command here is dead. If you need to call it dynamically, write the command as a batch file (linux write shell script)
You can also use process.exec(‘test.bat’, ...) and process.exec(‘sh test’,...) Execute file
The command here is write dead. If you need dynamic call, write the command as a batch file (linux write shell) Script)
You can also use process.exec(‘test.bat’,...) and process.exec(‘sh test’,...) to execute the file
Is to use the node.js command line to execute the linux command method, master this method, whether it is executed on the server or the host can be more comfortable.
In the Ubuntu system, many users report that when using Git, they often encounter the need to enter
Users who are still having trouble installing Bumblebee for Ubuntu notebooks have a
A lot of Linux beginners cant find the apue.h file mentioned in the article when they study the book
Usually Gentoo systems have their own upgrades. If the system cannot be upgraded automatically, how
Linux when the program is prompted to error while loading shared?
Linux uses PXE to install virtual machines
The specific steps of hard disk partitioning under Linux
Linux refuses foreign IP access steps
Linux how to use the ss command to view the socket status
Linux using virtual machine to install Windows 10
How to view Linux mounted disk
Linux ifconfig command usage summary
Wget command operation example
What are the ways to clean up Linux disk space?
Samsung notebook Win7 unexpected blue screen appears 0x0000000A code response measures
Device Driver Rating Strategy for Vista Systems
What should I do if the keyboard of the Win7 system fails?
How to completely uninstall NVIDIA graphics driver in windows7
How to set whether to merge or hide the label in Win8
Seeking to configure a computer with about 50,000 yuan
How does the Win10 system calibrate the monitor color? Win10 method of calibrating the display color