36

The Custom tasks section of the Tasks in Visual Studio Code describe the task's properties. There is a type property that define task's type:

type: The task's type. For a custom task, this can either be shell or process. If shell is specified, the command is interpreted as a shell command (for example: bash, cmd, or PowerShell). If process is specified, the command is interpreted as a process to execute.

I couldn't understand what's the different between them. No matter I choose shell or process, all the execute results are all the same.

So what's the different between interpreted as a shell command and command is interpreted as a process to execute really mean?

Nurbol Alpysbayev
22.4k6 gold badges68 silver badges100 bronze badges
asked Jan 22, 2019 at 11:07

3 Answers 3

35

The shell commands can only run inside a shell such as DIR for cmd and if for bash. So when you want to run shell commands, you have to use "type": "shell" setting to run it correctly. When you want to just run a program such as .bat, .sh or .exe, then you can just use "type": "process" setting.

answered Jan 22, 2019 at 12:58
Sign up to request clarification or add additional context in comments.

9 Comments

You're a real hero.
So I should be defaulting to process? Does it spawn a cmd too or am I saving that time? What's the benefit of process is what I'm asking I guess.
That does not really answer what the pro/con arguments are
I agree with @Razze that the pro/con arguments are still not answered. What's the benefit of using the "process" type when executing a program when I could just as easily use the "shell" type for calling said program? They offer the "process" type for some reason, but what is it? What do I gain by switching to "process" for a single program command? I can't find that answer in the docs.
@WillHuang, well yes. If I want to use any additional logic in the commands, aside from the program name, I would need to use the "shell" type. But again, I could still just use the "shell" type for the program name, and as far as I know, the result will be the same as using the "process" type. So that still doesn't answer the question of "why should I ever choose the 'process' type?"
|
7

I think the difference is as follows:

  • process: runs a specific program (a binary)
  • shell: starts a shell session and runs the given command inside of that shell session

If the command you give to a shell is just (the path to) a program, for example date, the result will be exactly the same.

{
 "version": "2.0.0",
 "tasks": [
 {
 "label": "example1",
 "type": "process",
 "command": "date",
 "presentation": {
 "reveal": "always"
 },
 "problemMatcher": []
 },
 {
 "label": "example2",
 "type": "shell",
 "command": "date",
 "presentation": {
 "reveal": "always"
 },
 "problemMatcher": []
 }
 ]
}

The task that uses process will probably be a little faster because it does not start a shell session.

But because a shell type task creates a shell session it can use any command you can type on the command line. So let's say the task we want to run is date -u +"%Y-%m-%dT%H:%M:%SZ", we can do this with a shell task, but not with a process task.

Example:

{
 "version": "2.0.0",
 "tasks": [
 {
 "label": "example1",
 "type": "process",
 "command": "date",
 "presentation": {
 "reveal": "always"
 },
 "problemMatcher": []
 },
 {
 "label": "example2",
 "type": "shell",
 "command": "date -u +\"%Y-%m-%dT%H:%M:%SZ\"",
 "presentation": {
 "reveal": "always"
 },
 "problemMatcher": []
 }
 ]
}

So, as always, it depends on what you need or want. Personally I think tasks of type shell are useful way more often.


One extra thing: a task definition can also have a "args" key where you can send arguments. That may allow you to send arguments if you need to use process. I did not investigate that to answer this question.

Another relevant page of docs.

answered Oct 23, 2022 at 9:27

Comments

4

well, I recently troubled by a problem, and I finally done it by changing the type from "process" to "shell" and I think this might help you: I'm trying to run more than one .cpp files, and I used a wildcard in the args:"${fileDirname}/.cpp". When the type was process, I cannot run the project successfully, as it always tell me: "*.cpp":no such file or directory and when I change to "shell" it goes well. This might be one of the differences between "process" and "shell".

answered Nov 23, 2020 at 11:58

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.