gpt4 book ai didi

node.js - shelljs "not found"错误

转载 作者:太空宇宙 更新时间:2023-11-04 00:10:03 26 4
gpt4 key购买 nike

我有以下 .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

最佳答案

它确实有效,只需将 #!/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});

terminal output :

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

关于node.js - shelljs "not found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50194826/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com