shelljs "не найдена" ошибка - PullRequest
0 голосов
/ 06 мая 2018

у меня ниже .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

Когда я запускаю его напрямую с ./ping.sh 8080, он работает нормально. Однако, когда я запускаю его с 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

1 Ответ

0 голосов
/ 06 мая 2018

Это работает, просто добавьте #!/bin/bash к ping.sh


Рабочее подтверждение концепции:

ping.sh

#!/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

ping.js

require('shelljs').exec("./ping.sh 8080", {async:true});

вывод терминала:

node ping.js
pinging http://localhost:8080/ping
resp 000
resp 000
...