Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js shelljs";“未找到”;错误_Node.js_Shell_Shelljs - Fatal编程技术网

Node.js shelljs";“未找到”;错误

Node.js shelljs";“未找到”;错误,node.js,shell,shelljs,Node.js,Shell,Shelljs,我有下面的.sh文件 // ping.sh 01: port="$1" 02: echo "pinging http://localhost:$port/ping" 03: 04: retry=0 05: while 06: sleep 1 07: api_response=$(curl --write-out %{http_code} --silent --output /dev/null "http://localhost:$port/ping") 08: echo

我有下面的.sh文件

// ping.sh
01: port="$1"
02: echo "pinging http://localhost:$port/ping"
03: 
04: retry=0
05: while
06:     sleep 1
07:     api_response=$(curl --write-out %{http_code} --silent --output /dev/null "http://localhost:$port/ping")
08:     echo "resp $api_response"
09:     (( "$api_response" != "200" && ++retry < 100 ))
10: do :; done

它确实有效,只需添加
#/bin/bash
ping.sh


工作概念证明: 平 终端输出:
shelljs中似乎不支持(())语法,我认为这只适用于bashI将其转换为for循环,但现在我在这行
中得到了相同的错误,如果[“$api_response”==“200”];然后
。恐怕我会切换到
child\u process
而不是
shelljs
这样的库为什么不呢?
// ping.js
require('shelljs').exec("./ping.sh 8080", {async:true});

$ node ping.js 
pinging http://localhost:8080/ping
resp 000 ./ping.sh: 9: ./ping.sh: 000: not found
#!/bin/bash
port="$1"
echo "pinging http://localhost:$port/ping"

retry=0
while
 sleep 1
 api_response=$(curl --write-out %{http_code} --silent --output /dev/null "http://localhost:$port/ping")
 echo "resp $api_response"
 (( "$api_response" != "200" && ++retry < 100 ))
do :; done
require('shelljs').exec("./ping.sh 8080", {async:true});
node ping.js
pinging http://localhost:8080/ping
resp 000
resp 000