How to execute terminal commands in nodejs?

how do I execute commands such as vue create xxx in the node script?

I want to be an active scaffolding. I want to learn from the idea of vue-cli , provide some options to developers, and then automatically generate project templates according to the developer"s choice. For example, if the developer chooses to use vue , then call the command of vue-cli to generate the template (some business-related things will be done in between), but after executing vue create xxx in the script with execa , it will not be called normally, but the terminal will not respond. But execute commands like git init .

call Creator function
clipboard.png

vue create xxx
clipboard.png

after receiving the parameter.
Jul.29,2021

you can use shelljs module

npm install shelljs
require('shelljs/global');

// Sync call to exec()
var version = exec('node --version', {silent:true}).output;

// Async call to exec()
exec('vue create xxx', function(status, output) {
  console.log('Exit status:', status);
  console.log('Program output:', output);
});

two ways:

1. Create using the child process child_process , including related packages, such as shelljs/shelljs" rel=" nofollow noreferrer "> shelljs , and execa in your code is also an encapsulation.

correct use of execa should be like this:

execa.shell(command, [options])

2. Call

directly in the code
require('@vue/cli/bin/vue');

I don't know much about vue-cli . You need to know more about it, such as whether you can add a callback function

.

encounters the same problem, try not to solve


does the landlord have a solution? I have the same problem

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3857f-2b653.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3857f-2b653.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?