2

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?

1 Answer 1

2

Turns out it works by sending all commands and parameters separately, and concatenating the different commands via a separate "command" &&:

child_process.spawn('wsl', ['source', '/path/to/virtualenv/env/bin/activate', '&&', 'which', 'python'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.