Running shell task in VSCode says "file not found" - visual-studio-code

I'm trying to create a custom shell task following the official documentation.
When running the task with CTRL+SHIFT+B, it returns
/usr/bin/bash: line 1: /usr/bin/daps-xmlformat: File not found
I cant see while the task cannot find the command when i supply the absolute path there?
Any ideas?
My code looks like this:
"tasks": [
{
"label": "Daps: XML format",
"type": "shell",
"command": "/usr/bin/daps-xmlformat",
"args": ["${file}"],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true,
"close": false
},
"options": {
"cwd": "${fileDirname}",
},
}
]

Found the glitch. I was using the flatpak version of VSCodium and it has limited access to the host file system. RPM version works great.

Related

Devcontainer: how to open terminal with custom commands when opening the container?

When starting my devcontainer, I need to run multiple commands to be able to work on my project. For example for my Django project, I need to run:
python manage.py runserver
celery -A proj worker
celery -A proj beat
tailwindcss -w -i input.css -o output.css
Currently, I do this manually and this is a little bit painful.
I know there is a postStartCommand that I could use, but I'd be forced to group all my commands with && and I would not be able to follow each command logs individually.
What I'd like to do is to automate what I'm currently doing by hand: open different terminal windows and run a single command in each of them, to have this result:
Is there a way to do that? Or any workaround? Thanks.
You can automate things in VSCode using custom tasks.
Your scenario is a bit tricky though, so, I'd suggest:
Create 3 separate tasks that open a terminal and execute one of the commands that you need. Check this answer for an example of how it's done.
Create a compound task that runs the 3 tasks above.
As a complement to #Dorin Botan good answer, here is my configuration in tasks.json, using 2 groups of terminals like this:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// See https://code.visualstudio.com/docs/editor/tasks-appendix
"version": "2.0.0",
"tasks": [
{
"label": "Term 1",
"type": "process",
"command": "/bin/bash",
"isBackground": true, // removes the infinite spinner
"problemMatcher": [],
"presentation": {
"group": "main_tasks",
"reveal": "always",
"panel": "new",
"echo": false, // silence "Executing task ..."
}
},
{
"label": "Django server",
"type": "shell",
"command": "./manage.py runserver 127.0.0.1:8000",
"isBackground": true,
"presentation": {
"group": "main_tasks",
"reveal": "always",
"panel": "new",
}
},
{
"label": "Celery worker",
"type": "shell",
"command": "celery --app dj_config worker --uid=nobody --gid=nogroup --loglevel INFO",
"isBackground": true,
"presentation": {
"group": "background_tasks",
"reveal": "never",
"panel": "new",
"showReuseMessage": false,
}
},
{
"label": "Celery beat",
"type": "shell",
"command": "celery --app dj_config beat --uid=nobody --gid=nogroup --loglevel INFO",
"isBackground": true,
"presentation": {
"group": "background_tasks",
"reveal": "never",
"panel": "new",
"showReuseMessage": false,
},
},
{
"label": "Tailwind watcher",
"type": "shell",
"command": "sleep infinity", // FIXME with real command
"isBackground": true,
"presentation": {
"group": "background_tasks",
"reveal": "never",
"panel": "new",
"showReuseMessage": false,
}
},
{
// This is a compound task to run them all
"label": "Mango Terminals (David)",
"dependsOn": [
"Term 1",
"Django server",
"Tailwind watcher",
"Celery worker",
"Celery beat",
],
"dependsOrder": "parallel", // no dependencies between tasks
"problemMatcher": [],
}
]
}

How to re-use a VS Code task window, without closing it

My goal is to re-use a task window in VS Code. However, when I enter ctrl + c, the task stops, but then writes: "Terminal will be reused by tasks, press any key to close it.".
I don't want to close the window. It's frustrating because it forces me to open a new window and navigate to the correct directory.
I recorded a gif of the problem (It's the window on the right):
My task config look like this:
{
"label": "some label",
"type": "npm",
"script": "build",
"path": "some-path/",
"problemMatcher": [],
"runOptions": { "runOn": "folderOpen" },
"group": "build",
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": false,
"group": "build"
}
}
I tried various combination of the presentation properties, but to no help.
Related feature request on VS code is here.
I don't think this is possible and it may be by design.
If you look at the schema of tasks.json, you see:
/**
* The description of a task.
*/
interface TaskDescription {
/**
* The task's name
*/
label: string;
/**
* The type of a custom task. Tasks of type "shell" are executed
* inside a shell (e.g. bash, cmd, powershell, ...)
*/
type: 'shell' | 'process';
//...
}
The type of a custom task. Tasks of type "shell" are executed inside a shell
So to me this implies that if you have a countdown task of type "shell" running this command seq 10 1, behind the scene it would do:
devbox:~ dev$ bash -c "seq 10 1"
10
9
8
7
6
5
4
3
2
1
devbox:~ dev$
As you can see it immediately exits and I'm not sure you can do anything about it. (I may be wrong though)
Even if you set a task of type "process" (command being the path to an executable), it doesn't allow you to reuse the terminal.
Having said that you can force it but VS Code wouldn't be too happy about it: (notice the && sh at the end of the command)
{
"version": "2.0.0",
"tasks": [
{
"label": "10 9 8 ...",
"type": "shell",
"command": "seq 10 1 && sh",
"presentation": {
"echo": true,
"focus": true,
"reveal": "always",
"panel": "shared",
},
"problemMatcher": [],
}
]
}
When you run the task, you do get another shell immediately:
However if you re-run the same task, then VS Code gets grumpy:
The fact that I couldn't see an option in .vscode/settings.json to support your use case makes me think that it really is a by design choice:
I found yet another solution for this that works great for me:
using bash:
"tasks": [
{
"label": "start server",
"type": "shell",
"command": "bash -c 'cd backend && npm run dev; exec bash'",
"isBackground": false,
"presentation": {
"panel": "new",
"close": true
},
"runOptions": {
"runOn": "folderOpen"
}
}
]
or if you use fish (like me):
"tasks": [
{
"label": "start server",
"type": "shell",
"command": "fish -C 'cd backend && npm run dev'",
"isBackground": false,
"presentation": {
"panel": "new",
"close": true
},
"runOptions": {
"runOn": "folderOpen"
}
}
]
It sounds like you want to launch a shell in the right folder after the task is complete. I'm not sure if this is the best way to do it, but I do something similar with compound tasks.
{
"label": "some label",
"type": "npm",
"script": "build",
"path": "some-path/",
"problemMatcher": [],
"runOptions": { "runOn": "folderOpen" },
"group": "build",
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": false,
"group": "build"
}
},
{
"label": "shell",
"type": "shell",
"command": "cd app; bash",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Task and Shell",
"group": "build",
"dependsOn": ["some label", "shell"],
"dependsOrder": "sequence",
}
This configuration runs bash in the right folder after the task (in the same window). Replace bash with whatever shell you use if necessary.
I found a solution for this, my task looks something like this
"tasks": [
{
"label": "start server",
"type": "shell",
"command": "RUN='cd backend && npm run dev' bash",
"problemMatcher": [],
},
]
and at the end of my .bashrc I have eval "$RUN"

Tasks - Windows Command Task with multiple commands

I have a problem when I try to run a make task that runs in a windows command shell. I've tried various combinations but I can't get the command to fully execute.
In tasks.json below you can see I've tried various methods (this format gives me the most info) but in all attempts the make file command fails "'make' is not recognized as an internal or external command, operable program or batch file." yet its the script setCmdEnv in the first command which sets up the make path etc.
The first two commands work fine, I can't see why the last command doesn't execute correctly.
Weirdly I can type make after the shell is loaded (after the error) and all is ok.
{
"version": "2.0.0",
"type":"shell",
"windows": {
"options": {
"shell": {
// "executable": "C:\\WINDOWS\\System32\\cmd.exe",
"executable": "",
// "args": [
// "/K .\\BuildEnv\\xBuildEnv\\setCmdEnv && cd .\\app && "
// ]
}
}
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"clear": false
},
"tasks": [
{
"label": "Make %1.test",
"command": "cmd.exe",
"args": [
" /K .\\BuildEnv\\xBuildEnv\\setCmdEnv && cd .\\app && make ${fileBasenameNoExtension}.test"
],
"problemMatcher": []
}
],
}
I had a similar issue and to make the Visual Studio Code task to execute multiple commands, I had to separate each elements of the args array to leave out any white space. So in this case, the task could be something like this:
{
"version": "2.0.0",
"tasks": [
{
"label": "Make your test file",
"type": "shell",
"windows": {
"command": "%comspec%",
"args": ["/C", "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\VsDevCmd.bat",
"&&", "cd", ".\\apps", "&&", "make", "${fileBasenameNoExtension}.test"
]
},
"options": {
"cwd": "${workspaceRoot}"
},
"presentation": {
"showReuseMessage": false,
"reveal": "always",
"panel": "shared",
"group": "test",
"clear": true,
"focus": true
}
}
]
}
Note: The %comspec% variable resolves to C:\WINDOWS\system32\cmd.exe.

How can I see compiler's output when running task in Visual studio code?

Everytime I try to run the build task, I can't see anything except from The terminal process terminated with exit code: 1, how can I configure VSCode so I can see compiler's output?
Below is my task file and what I've got from running build task:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "C:/Program Files (x86)/Dev-Cpp/MinGW32/bin/g++",
"args": [
"-g",
"mysockets.cpp"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true
},
"problemMatcher": "$gcc",
},
]
}

How to configure a VSCode Task to run a powershell script in the integrated terminal

In such a way that it is not in a sub shell. I need it to be able to prepare the environment...set environment variable.
"version": "0.1.0",
"command": "${workspaceFolder}/Invoke-Task.ps1",
/*"command": "powershell", creates subshell so doesn't work*/
"isShellCommand": false,
"args": [],
"showOutput": "always",
"echoCommand": true,
"suppressTaskName": true,
"tasks": [
{
"taskName": "task1",
"args": ["task1"]
},
{
"taskName": "task2",
"args": ["task2"]
}
]
I am sorry, but you are not correctly editing the .vscode/tasks.json file.
In your scenario, lets say you have some powershell script ./scripts/mycustomPSscript.ps1 you want to run as a vscode task. For such goal, edit the tasks file so it follows the below example:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run-some-custom-script",
"detail": "Prepare some ENV variables for the deployment",
"type": "shell",
"command": "./../scripts/mycustomPSscript.ps1",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
}
}
]
}
This has been doable since 2017, if I get your ask correctly.
integrated-terminal-tasks README This extension allows a workspace to
define specific tasks that should be ran in VSCode's interactive
terminal
https://marketplace.visualstudio.com/items?itemName=ntc.integrated-terminal-tasks
Also, your post / query, could been seen as a duplicate of this...
Run Code on integrated terminal Visual Studio Code
Adding this configuration in the launch.json file did the trick for me
"version": "0.2.0",
"configurations": [
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Launch Current File",
"script": "put full path here\\launch.ps1",
"args": ["${file}"],
"cwd": "${file}"
},...
Not sure what you mean by 'integrated terminal' but the output does show up in the VSC terminal if this is what you're referring to.