首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >shelljs“未找到”错误

shelljs“未找到”错误
EN

Stack Overflow用户
提问于 2018-05-05 23:11:45
回答 1查看 1.2K关注 0票数 1

我有下面的.sh文件

代码语言:javascript
复制
// 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运行它时,它会出现以下错误。

代码语言:javascript
复制
// 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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-05 23:53:48

它确实有效,只需将#!/bin/bash添加到ping.sh中即可。

概念的工作证明:

ping.sh

代码语言:javascript
复制
#!/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

代码语言:javascript
复制
require('shelljs').exec("./ping.sh 8080", {async:true});

终端输出:

代码语言:javascript
复制
node ping.js
pinging http://localhost:8080/ping
resp 000
resp 000
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50194826

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档