2

In my package.json, I have scripts that open in new terminals using "start" (Windows OS only):

"automation": "start npm run webdriver:start && npm run timeout"
"webdriver:start": "webdriver-manager start",
"timeout": "timeout 3",

My question is how do I then close that terminal window once the action is complete?

I have tried the following but neither close the terminal window:

"automation": "(start npm run webdriver:start && npm run timeout) && exit"
"automation": "(start npm run webdriver:start && npm run timeout) && exit 1"

When I do just an "exit" in a Windows terminal, it does close the window but it doesn't seem to work in the script. Any help is much appreciated.

Running the following command:

npm run automation
awhisler
  • 21
  • 3
  • Try this: `cmd.exe /c "npm run webdriver:start && npm run timeout"` cmd.exe is a Windows command-line shell, from the help: /C Carries out the command specified by string and then terminates – Soonts Jan 23 '20 at 21:50
  • Is that for powershell? I'm not running in powershell. Also that will not work outside of the string as the syntax for package.json will not allow that – awhisler Jan 23 '20 at 22:49
  • https://stackoverflow.com/a/15637481/126995 – Soonts Jan 23 '20 at 23:22
  • Still not sure what you're getting at. In the scripts in the package.json I cannot put `cmd.exe /c` outside of the string. And I'm not sure how three slashes will help. Can you give me the exact example of how to write it for package.json format? – awhisler Jan 24 '20 at 15:43
  • You need to escape the quotes like this: "automation": "cmd /c \"(start npm run webdriver:start && npm run timeout) && exit\"", however i've tried @Soonts answer and i didn't manage to get it work from vscode – luiscla27 Jan 30 '20 at 19:24
  • Also check this: https://stackoverflow.com/questions/47946868/how-to-get-rid-of-terminal-will-be-reused-by-tasks-press-any-key-to-close-it – luiscla27 Jan 31 '20 at 22:37

1 Answers1

0

VSCode doesn't allows to close the terminal from the script (check this issue), how ever you can just "silence" the newly open terminal, for that you'll have to modify your tasks.json file by adding the reveal, clear and showReuseMessage to it.

Your tasks.json file should end up to something like this:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "npm",
            "script": "automation",
            "problemMatcher": [],
            "presentation": {
              "reveal": "silent",
              "clear": true,
              "showReuseMessage": false
            }
        }
    ]
}

If you'r task.json file is missing check this other question.

luiscla27
  • 4,956
  • 37
  • 49