Moiz Ahmed
Moiz Ahmed

Reputation: 131

Run bash script in WSL through powershell script

I am trying to run a script which launches a WSL (ubuntu1804) terminal, and then run a bash script in that terminal

.\ubuntu1804.exe;
cd test_directory;
node server.js;

However after the first command the terminal open however, the two other commands aren't executed

Upvotes: 3

Views: 2489

Answers (1)

mklement0
mklement0

Reputation: 437042

.\ubuntu1804.exe by itself opens an interactive shell which PowerShell executes synchronously.

That is, until you submit exit in that interactive shell to terminate it, control won't be returned to PowerShell, so the subsequent commands - cd test_directory and note server.js - are not only not sent to .\ubuntu1804.exe, as you intended, but are then run by PowerShell.

Instead, you must pass the commands to run to .\ubuntu1804.exe via the run sub-command:

.\ubuntu1804.exe run 'cd test_directory; node server.js'

Note: Once node exits, control will be returned to PowerShell.

Upvotes: 3

Related Questions