What I am trying to do :
I am trying to spawn a background process and redirect its output to VSC's shell. This background process should be independent from the parent shell, because VSC will wait until the shell that spawned it (the parent shell) sends an exit code.
startWebpack.sh
#!/bin/bash
echo "Starting webpack-dev-server"
cd .. && cd client && yarn debug
Command
./startWebpack.sh &
What I am doing :
Following this guide I should be able to spawn a background process by appending a &
after a script. It doesn't seem to make the script independent from the parent.
The parent shell seems to take over the output of the background process and never sends the exit signal. Killing the parent shell then also kills the background process.
Sending the output to /dev/null
with ./startWebpack.sh > /dev/null
did not make any difference. I could actually still see the output of that command.
VSC runs the command internally with bash -c ./startWebpack.sh &
source. Not sure if that is affecting anything.
> /dev/null
redirects the output to /dev/null, but there are 3 files associated with any running task: input, output and error, which are file ids 0, 1 and 2. Input won't really be noticeable unless the script expects something from the user, but you need to deal with the error channel. The syntax noted in the answer below deals with both stdout and stderr with>/dev/null 2>&1
, which tells the program to send output to /dev/null and error output (file 2) to wherever file1 is sending output. – Fubar Jun 09 '20 at 15:43