通过powershell脚本在WSL中运行bash脚本

通过powershell脚本在WSL中运行bash脚本,powershell,windows-subsystem-for-linux,Powershell,Windows Subsystem For Linux,我试图运行一个启动WSL(ubuntu1804)终端的脚本,然后在该终端中运行一个bash脚本 .\ubuntu1804.exe; cd test_directory; node server.js; 但是,在第一个命令打开终端后,其他两个命令不会执行\ubuntu1804.exe本身会打开一个交互式shell,PowerShell会同步执行该shell 也就是说,除非您在该交互式shell中提交退出以终止它,否则控件不会返回到PowerShell,因此后续命令--cd test_direct

我试图运行一个启动WSL(ubuntu1804)终端的脚本,然后在该终端中运行一个bash脚本

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

但是,在第一个命令打开终端后,其他两个命令不会执行

\ubuntu1804.exe
本身会打开一个交互式shell,PowerShell会同步执行该shell

也就是说,除非您在该交互式shell中提交
退出
以终止它,否则控件不会返回到PowerShell,因此后续命令--
cd test_directory
note server.js
,不仅不会像您预期的那样发送到
\ubuntu1804.exe
,而是由PowerShell运行

相反,您必须通过
run
子命令将要运行的命令传递给
\ubuntu1804.exe

.\ubuntu1804.exe run 'cd test_directory; node server.js'
注意:一旦
节点退出,控件将返回到PowerShell