-
Notifications
You must be signed in to change notification settings - Fork 29.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using WSL - Running a task using existing environment variables and without the "Press any key to close the terminal" requirement #24967
Comments
@dbaeumer May should be able to look into this further. As a workaround, can you try using a script:
{
"version": "2.0.0",
"isShellCommand": true,
"tasks": [
{
"taskName": "test",
"command": "./run.sh",
"args": [
"compile"
]
}
],
"showOutput": "always"
}
#!/bin/bash
source ~/.bashrc
tsc "$@" You may have to |
@mjbvz I did find something similar and it works indeed for the environment variables. But it would be so much easier if the |
@Tyriar any idea why these environment variables are not source from .bashrc. All the task framework does is to create a terminal with the default settings and passing -c to close the bash after executing? @electrotype there is no need to close the terminal after every run. If you press Ctrl+Shift+B a second time the terminal is actually reused. So it behaves like a 'single' build command output. What we plan to add is a options to close the terminal automatically. But showing the output in the output channel will not happen since it would require to have full ANSI support in the output windows. This is why we move to the terminal. |
AFAIK the env should be set when you use |
@dbaeumer I understand for the terminal, thanks. @Tyriar :
The three variables I need are there. And running the
|
@electrotype I mean configure your tasks.json to run |
Sorry about that. Here's the output :
And here's the task I use :
In my user settings :
|
I think this is an issue with WSL that |
I found the WSL issue about this : .bashrc not used when If I understand it properly, this is not something they are going to fix though! Does this mean that it may be up to VSCode to change the way it calls |
I read through the referenced issue and we need to change starting bash in the task framework to something like bash -c "source ~/.bashrc; |
Try using |
The reason for this is the following code block at the beginning of the .bashrc file in the Ubuntu subsystem:
The actually exit the .bashrc when not in interactive mode. As @nelak points out to source the .bashrc when running a command -c you need to pass -i -c. I am reluctant to make it the default since running a command should usually not source the .bashrc since it might alter the environment again. |
The solution for this would be to let the user control whether to source the env or not when executing a task. As a workaround for now this can be done:
|
Since the need to control the sourceing of the bashrc is small and a way to control this via the There is a general issue to track tasks to be executed in WSL. |
This iteration we focus on issue grooming. This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider. If you wonder what we are up to, please see our roadmap and issue reporting guidelines. Thanks for your understanding and happy coding! |
@dbaeumer Sorry for the dumb question - could you help elaborate on how do I set my I used the following and it seems to be working. If you don't mind, could you help confirm that I was doing right, and maybe future readers may also benefit from this small change?
|
@yw5aj yes this is the correct way to configure this. |
I use Bash On Ubuntu On Windows, and I try to make it my default terminal in VSCode. In my
User Settings
:It is a Node application written in TypeScript. I use Gulp to run tasks and it works well if I use the terminal directly. But now I try to make
CTRL-SHIFT-B
run the build command task, which has to call "node_modules/.bin/gulp compile
" to run the transpilation from TypeScript to Javascript.Thanks to this thread, I'm able to at least start the compilation with this
tasks.json
file :The compilation starts but fails because it involves the
oracledb
library which needs some environment variables to be set :When I run
env
directly in the terminal, I see those variables since they are exported in my~/.bashrc
file, and this is why the direct compilation works. But when the compilation is ran from the task, those variable are not set, for some reason!How can I make the task to automatically source my
~\.bashrc
file? Or should I define the exports in another file for them to work?At the end of the task, a "Press any key to close the terminal" message is displayed. Is there a way to output the task to the "output" console instead? Or at least is it possible to remove the requirement to press a key at the end? I'd prefere to not have to do that each time I build using
CTRL-SHIFT-B
.The text was updated successfully, but these errors were encountered: