Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Problems with exiting from CLI #1050

Open
amadeus-8 opened this issue Sep 22, 2021 · 4 comments
Open

Problems with exiting from CLI #1050

amadeus-8 opened this issue Sep 22, 2021 · 4 comments

Comments

@amadeus-8
Copy link

I've created simple CLI using inquirer and child_process. And i have problem, when i'am closing process with CTLR+C, it seems like its still running process, because terminal not responding anything. And i have to close terminal every time and open it again, it's uncomfortable for me. What i need to do, to exit all processes with simple CTRL+C command? Searched so many solutions in google, but no result. Hope somebody can help me with it

const inquirer = require('inquirer')
const { execSync } = require('child_process')
const { readdirSync } = require('fs')

const targetFolder = './src/pages'

const directories = readdirSync(targetFolder)

const questions = [
    {
        type: 'list',
        name: 'page',
        message: 'Choose page to compile',
        choices: directories,
    },
]

inquirer.prompt(questions).then(({ page }) => {
    const options = {
        stdio: 'inherit',
    }
    execSync(`npm run start -- --env page=${page}`, options)
})
@raskyer
Copy link

raskyer commented Sep 3, 2024

We have the same issue on Powershell when hitting CTRL+ C:

ExitPromptError: User force closed the prompt with 0 null
    at path\node_modules\@inquirer\core\dist\cjs\lib\create-prompt.js:60:28
    at Emitter.emit (path\node_modules\signal-exit\dist\cjs\index.js:71:19)
    at #processEmit (path\node_modules\signal-exit\dist\cjs\index.js:240:27)
    at #process.emit (path\node_modules\signal-exit\dist\cjs\index.js:191:37)
    at process.callbackTrampoline (node:internal/async_hooks:128:17)

@SBoudrias
Copy link
Owner

@raskyer is it the same issue? Is the problem the error itself? Or that even with the error the prompt doesn't exit?

@raskyer
Copy link

raskyer commented Sep 3, 2024

I have both, for the error message I have fixed it with the solution from another ticket. I have added process.exit(0) in the catch and it seems to fix the issue but without it it's hanging.

@SBoudrias
Copy link
Owner

SBoudrias commented Sep 3, 2024

process.exit() forces the process to exit immediately.

Without it, Node waits for timeouts and other scheduled async operations to complete in order to safely exit. That's not specific to Inquirer.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants