64

Upon executing a task (cargo build in this case), the following appears in the VSCode terminal:

> Executing task: cargo build <

(output of the task here)

Terminal will be reused by tasks, press any key to close it.

Annoyingly, this takes me out of the normal terminal and then I have to acquire focus of the terminal window and press a key to get back. And when I do so, the output of cargo build disappears.

How do I stop this behaviour?

How do I get rid of the first and last lines of text?

A.B.
  • 15,364
  • 3
  • 61
  • 64
  • I am also wondering how to get rid of it. I am using "dependsOn"-feature. At the moment i need to go to console to multiple times click any key. – Antti Jan 14 '18 at 17:09
  • Same problem. I didn't have problems with it earlier. Is it a version or system dependent problem? – cerebrou Feb 15 '18 at 07:59
  • I would like to automatically close the old terminal when I execute a new task. I have students reading old error messages because they assume *all* the terminal content is freshly created after a task. – user2023370 Mar 11 '20 at 17:40

6 Answers6

63

Check if the new feature from VSCode 1.57 (May 2021, 2.5 years after the OP) could help:

Automatically close task terminals

The task presentation property has a new close property.
Setting close to true will cause the terminal to close when the task exits.

{
  "type": "shell",
  "command": "node build/lib/preLaunch.js",
  "label": "Ensure Prelaunch Dependencies",
  "presentation": {
      "reveal": "silent",
      "revealProblems": "onProblem",
      "close": true
  }
}

[EDIT: 18-08-2018] Making it switch into the Problems tab is better when using the close option as that ensures the task terminal is closed, but the problems are properly highlighted. This is from VSCode 1.59.0.


Danin adds in the comments:

After fiddling around, I found an easy way to do it in-app;
Terminal > Configure Tasks > (select your desired task) > add "presentation": { .. } block to level containing matching "task:" entry.

Danin also mentions:

I also omitted the "reveal" entry because I prefer to see the terminal briefly -- it just interferes with workflows to have it stick around.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 7
    This should now be the accepted solution based on the evolution of VS Code and its ability to close automatically a terminal after the execution of a command. – Samuel Sep 08 '21 at 14:01
  • 2
    The "presentation" key is to be added into the file tasks.json as a key to "task" dictionary in the file. – Baraa Apr 12 '22 at 19:44
  • 2
    This worked for me, thank you. When it has issues, they go into the `Problems` tab – Aron Atilla Hegedus Jul 19 '22 at 09:54
  • This is fantastic, but as a user with little experience "correcting" VSCode, it leaves me with no actual answer. Even with the source link, I don't have the context to decypher which part instructs one on where to put this block of information. Can we please clarify with a filename/path? – Danin Mar 14 '23 at 20:22
  • After fiddling around, I found an easy way to do it in-app; Terminal > Configure Tasks > (select your desired task) > add "presentation": { .. } block to level containing matching "task:" entry. – Danin Mar 14 '23 at 20:43
  • @VonC - Thanks!For what it's worth I also omitted the "reveal" entry because I prefer to see the terminal briefly -- it just interferes with workflows to have it stick around. Not sure if this is worthy of main-thread mention since it's a bit offtopic but I found it helpful. – Danin Mar 15 '23 at 22:09
26

To be clear, executing a task will always create a new integrated terminal in VS Code. There is no way around that. The most important thing is for the original terminal to be displayed instead of the newly created integrated terminal. (We want the original terminal revealed.)

@Gregory Cosmo Haun's solution will suppress the message "Terminal will be reused by tasks, press any key to close it". However, it still reveals the new integrated terminal instead of the normal terminal. (so you still have to press "any key" to close that terminal and reveal the original terminal)

A better solution would be to set "reveal": "silent", which will still create a new integrated terminal, but not reveal it unless there is an error while executing your task. I also set "clear": true (which is optional) so that the terminal is cleared before executing the task. I deliberately omit "showReuseMessage": false (which is optional) but you can add it. Who cares if the prompt is suppressed or not? The most important thing is that the newly created terminal is not revealed so I don't have to "press any key" to close it.

"presentation": {
  "reveal": "silent",
  "clear": true
}

BTW, you can also set "reveal": "never", but you would normally want to see the error message if there is a problem with executing your task.

In my opinion, this is the best possible solution. Yes, a new integrated terminal will always be created when executing a task, but at least it won't be revealed (unless there is an error) and you can safely ignore it without having to press any key to close it.

kimbaudi
  • 13,655
  • 9
  • 62
  • 74
8

There is a new presentation option called showReuseMessage. Add the following to your task definition.

"presentation": {
     "showReuseMessage": false
}
Gregory Cosmo Haun
  • 1,499
  • 17
  • 25
  • This worked perfectly for me in VSCode-win32-x64-1.34.0 – abelito May 27 '19 at 14:53
  • 8
    This literally only hides the message "`Press any key to close the terminal.`". You still need to press any key to see your terminal. – rustyx Jul 12 '19 at 17:27
  • 1
    I agree with @rustyx. This might suppress the message, but a new integrated terminal is revealed instead of the original terminal. A slightly improved solution would be to also set `"reveal": "silent"`. This way, you don't have to press any key. Please see my answer. – kimbaudi Aug 05 '19 at 08:54
  • Very nice explanation – Ravindra Singh Nov 09 '21 at 17:14
2

One possibility is to add the following command to the "tasks":

"presentation": {
            "panel": "new"
        },

as

"tasks": [
    {
        "label": "python",
        "type": "shell",
        "command": "python",
        "presentation": {
            "panel": "new"
        }
    }
]

This does not fully solve the problem but at least does not pile all the results one after the other in the panel.

Inspired by https://github.com/Microsoft/vscode/issues/35642

cerebrou
  • 5,353
  • 15
  • 48
  • 80
  • 1
    still prompts: Press any key to close the terminal. – Gang YIN May 02 '19 at 10:38
  • @GangYin - you still need to set `"showReuseMessage": false` to suppress the message. – kimbaudi Aug 05 '19 at 08:56
  • I don't think `"panel": "new"` is a good idea. This would add a new integrated terminal every time you launch the task. I think the default `"panel": "shared"` is perfectly fine and you should instead set `"showReuseMessage": false` and `"reveal": "silent"` – kimbaudi Aug 05 '19 at 09:00
  • This helps for https://github.com/jeremiah-c-leary/vhdl-style-guide integration into visual studio. Without it the second time you run it won't highlight results. – poleguy Jul 12 '23 at 18:40
2

An alternative solution is to set the output window to auto-focus.

Add this to the task definition:

    "presentation": {
        "focus": true
    }

Then it's not that annoying anymore because you can dismiss the compiler output with a single key press.

The benefit of this is that the task output is visible, so you can see if there were any errors or warnings.

rustyx
  • 80,671
  • 25
  • 200
  • 267
  • 1
    but this would mean you still have to "press any key" to close the integrated terminal that opens from launching a task. I would much prefer to silently ignore the prompt, which can be done by setting `"reveal": "silent"` and `"showReuseMessage": false` – kimbaudi Aug 05 '19 at 09:02
  • Yes, that's a solution for when one don't want to see the task output. – rustyx Aug 05 '19 at 11:44
  • I think that is the next best thing (to hide the task output), since its not possible to prevent the task output from being displayed. – kimbaudi Aug 05 '19 at 14:08
1

After upgrading to VSCode 1.69.0 I started seeing this. I found the simplest change is to add this to my tasks.json file:

    "presentation": {
        "showReuseMessage": false
    },

It's described here as:

  /**
   * Controls whether to show the `Terminal will be reused by tasks,
   * press any key to close it` message.
   */
  showReuseMessage?: boolean;
parsley72
  • 8,449
  • 8
  • 65
  • 98