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
shellorprocess. Ifshellis specified, the command is interpreted as a shell command (for example: bash, cmd, or PowerShell). Ifprocessis 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?
3 Answers 3
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.
9 Comments
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.
Comments
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".