Skip to content
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

Task doesn't execute bash commands in background (with &) #211851

Open
albaquarto opened this issue May 2, 2024 · 3 comments
Open

Task doesn't execute bash commands in background (with &) #211851

albaquarto opened this issue May 2, 2024 · 3 comments
Assignees
Labels

Comments

@albaquarto
Copy link

albaquarto commented May 2, 2024

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.88.1
  • OS Version: Ubuntu 22.04.4 LTS

Steps to Reproduce:

  1. I wrote a simple bash script calling a function that loops 5 times and call echo with a simple message. The function is called, the output redirected in a file and the process background
    Screenshot from 2024-05-02 18-00-17
  2. then in my workspace I created a task that calls this script
    Screenshot from 2024-05-02 18-04-05

If I run this script from the terminal it works fine
Screenshot from 2024-05-02 18-07-42
If I run my task the file is empty.
If I remove & the script is executed correctly in both, the terminal and the task
If I remove only the redirection (>>) nothing change about the execution, from terminal it works fine from tasks doesn't.
If I redirect sterr in stout and then background (2>&1) the result is the same

It seems that background command are not correctly executed.
I read similar issue (#199698) exists and was closed without solution but I can say that the problem exists and is not related to the command runned but to tasks

@Jean7667
Copy link

Jean7667 commented May 5, 2024

I have a similar issue on Linux as well. I had to installed an extension to make the task execution auto on startup first.
Then the command shows in terminal but it doesn't execute it. This is Simple script to activate a virtualenv.
I tried to execute the command inside the tasks.json file and it did not work. then I tried to use an extra script and call it in the task but i got the same behavior. Tasks is showing executed but nothing happened.
It seems that it is the same problem.
I created a question on stack overflow.
https://stackoverflow.com/questions/78430426/automating-a-task-with-visual-studio-does-not-work-as-expected

I think the issue is for every command shell, I tried to call an alias with the same command and it does not work.
the alias works fine when executed directly in the terminal but not in Visual Studio Code, it's possible that there could be an issue with how Visual Studio Code is configured to run tasks or how it interacts with the shell environment.

@albaquarto
Copy link
Author

albaquarto commented May 6, 2024

I have a similar issue on Linux as well. I had to installed an extension to make the task execution auto on startup first. Then the command shows in terminal but it doesn't execute it. This is Simple script to activate a virtualenv. I tried to execute the command inside the tasks.json file and it did not work. then I tried to use an extra script and call it in the task but i got the same behavior. Tasks is showing executed but nothing happened. It seems that it is the same problem. I created a question on stack overflow. https://stackoverflow.com/questions/78430426/automating-a-task-with-visual-studio-does-not-work-as-expected

I think the issue is for every command shell, I tried to call an alias with the same command and it does not work. the alias works fine when executed directly in the terminal but not in Visual Studio Code, it's possible that there could be an issue with how Visual Studio Code is configured to run tasks or how it interacts with the shell environment.

I think that your problem is not related to tasks but to shell. When you run a task vscode open a new shell, when your script run source the command is runned in the current shell, so when you open a new shell (not a subshell) maybe the env variables set by virtualenvwrapper are not present.
Background works in a different way, a background process running independent of the shell or Window Manager, So also if the shell opened to run the task is closed the background process would remain active. This is what I expected, but it doesn’t happen, on the contrary the process seems to be killed immediately

@Jean7667
Copy link

Jean7667 commented May 6, 2024

I updated #205177
There is 2 poitns

  • One is that the task executes in a second terminal and not in the current terminal with my zsh shell .

  • The second one is that in the second terminal the task is not executed whatever possible setting I have in the task.
    ie. when the task is terminated the virtualenv is not activated .

I tried to Use Direct Shell Commands: Instead of relying on aliases or shell-specific commands (like workon in virtualenvwrapper). I tried to change the type to process but nothing worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants