使用 NodeJS 创建 CLI - 将变量传递给 exec linux 命令
Creating CLI using NodeJS - Passing variable to exec linux command
我正在尝试使用 nodejs 和 commander.js 包创建一个简单的 CLI。
CLI 的目的是 touch 一个新文件
const program = require('commander');
const exec = require('child_process').exec;
program.version('0.0.1')
.description('Command Line Interface (CLI)');
program.command('make:controller <name>')
.description('Add a new controller called <name>')
.action(function (name) {
exec("touch name");
});
program.parse(process.argv);
命令:make:controller新控制器
Linux:触摸新控制器
如何将名称变量传递给 exec() 命令。
P.S(创建新文件后我也想往里面写点东西)
const program = require('commander');
const exec = require('child_process').exec;
program.version('0.0.1')
.description('Command Line Interface (CLI)');
program.command('make:controller <name>')
.description('Add a new controller called <name>')
.action(function (name) {
exec("touch " + name);//mind the space after touch
});
program.parse(process.argv);
像这样在exec(name)中传递变量。
program.command('make:controller <name>')
.description('Add a new controller called <name>')
.action(function (name) {
exec(name);
});
我正在尝试使用 nodejs 和 commander.js 包创建一个简单的 CLI。
CLI 的目的是 touch 一个新文件
const program = require('commander');
const exec = require('child_process').exec;
program.version('0.0.1')
.description('Command Line Interface (CLI)');
program.command('make:controller <name>')
.description('Add a new controller called <name>')
.action(function (name) {
exec("touch name");
});
program.parse(process.argv);
命令:make:controller新控制器
Linux:触摸新控制器
如何将名称变量传递给 exec() 命令。
P.S(创建新文件后我也想往里面写点东西)
const program = require('commander');
const exec = require('child_process').exec;
program.version('0.0.1')
.description('Command Line Interface (CLI)');
program.command('make:controller <name>')
.description('Add a new controller called <name>')
.action(function (name) {
exec("touch " + name);//mind the space after touch
});
program.parse(process.argv);
像这样在exec(name)中传递变量。
program.command('make:controller <name>')
.description('Add a new controller called <name>')
.action(function (name) {
exec(name);
});