簡體   English   中英

通過powershell腳本在WSL中運行bash腳本

[英]Run bash script in WSL through powershell script

我正在嘗試運行一個啟動 WSL (ubuntu1804) 終端的腳本,然后在該終端中運行一個 bash 腳本

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

但是,在終端打開的第一個命令之后,不會執行另外兩個命令

.\\ubuntu1804.exe本身打開一個交互式shell,PowerShell同步執行。

也就是說,除非您在該交互式 shell 中提交exit以終止它,否則控制權不會返回給 PowerShell,因此后續命令 - cd test_directorynote server.js - 不僅不會發送到.\\ubuntu1804.exe ,因為您打算,但隨后由 PowerShell運行。

相反,您必須通過run子命令將要運行的命令傳遞到.\\ubuntu1804.exe

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

注意:一旦node退出,控制權將返回給 PowerShell。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM