[英]Command not working inside execSync in nodejs
我有一個 shell 命令在終端上運行良好,但是當我嘗試從 nodejs 運行時,它給了我錯誤
原始命令
awk -v RS='"[^"]*"' '{n+=gsub(/\n/, "&")} END{print n}' <(sed '$s/$//' file.txt)
節點 Js 代碼
execSync("awk -v RS='\"[^\"]*\"' '{n+=gsub(/\\n/, \"&\")} END{print n}' <(sed '$s/$//' "+ filePath+')')
exesync 給出相同的 output 但它向我顯示錯誤語法錯誤:“(”意外
<()
是特定於 bash 的進程替換語法。 execSync
默認使用/bin/sh
,通常是嚴格符合 POSIX 標准的 shell,這意味着它不支持該語法。 明確使用 bash 代替:
execSync("command goes here", {
shell: "/bin/bash"
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.