We have a Windows NodeJS process which has to invoke some Linux commands via WSL. In a normal WSL bash session, we would just execute these commands one after the other:
user@pc:/mnt/c/Users/user$ command1 args1
user@pc:/mnt/c/Users/user$ command2 args2
However, when calling WSL via wsl command1 args1 and then wsl command2 args2, the results from the first call do not affect the second call. These are two sessions, not one.
I tried it like this: The first command is a virtualenv activate call, the second one is the execution of a Python script:
import { child_process } from 'mz';
child_process.spawn('wsl', ['source /path/to/virtualenv/env/bin/activate', 'which python'])
does not work, because the two arguments are interpreted as one command each (source /path/to/virtualenv/env/bin/activate: No such file or directory).
I also tried
child_process.spawn('wsl', ['source /path/to/virtualenv/env/bin/activate && which python'])
and
child_process.spawn('wsl', ['source /path/to/virtualenv/env/bin/activate `&`& which python'])
Does not work either.
How can I batch these two commands so that WSL and bash understand which commands belong together?