节点exec子进程立即退出

时间:2018-02-13 12:54:14

标签: javascript bash child-process

我有以下bash脚本:

#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "params:"
echo "ID: $1"
echo "Name: $2"

curl -u user:pass 
"https://scihub.copernicus.eu/dhus/odata/v1/Products('""$1""')/\$value" --
output $DIR/test/"$2".zip
wait
echo "download Product" "$2"

我通过具有此功能的节点子进程调用它:

function makeRequest(url, i, callback) {
var sys = require('util'),
    exec = require('child_process').exec,
    child;

var directory = __dirname.substring(0, __dirname.indexOf("\\app_api"));

console.log("executing:", directory + '\\downloadProducts.sh ' + url + ' ' + namesArray[i]);
child = exec(directory + '\\downloadProducts.sh ' + url + ' ' + namesArray[i]);
child.on("error", function (error) {
    console.log("child error:", error);

})

child.stdout.on('data', function (data) {
    console.log(data.toString());

});

child.on('close', function (exit) {
    console.log("child exit:", exit);

})
}

调用此函数后,子进程以代码0退出,而不等待curl请求完成。我还尝试了exit而不是close

我该怎么解决?提前谢谢。

0 个答案:

没有答案