Node.js陷入了回调

时间:2015-05-04 10:46:52

标签: javascript node.js asynccallback

我的代码陷入了这个功能。它进入了一系列回调。有人可以指导我完成它吗?

router.get('/search',function(req, res, next){
    //Check/Convert the selected query to MPEG
    //Color_Analysis.py -d path/to/query -c 1 :- outputs a file with 150 lines & Avg.py
    //back.py -d path/to/query :-  will generate file with 8/10 lines.
    //Audio.py index_number_of_query :- will output a vector of weights 
    //Combine all outputs and display the frame.
    console.log("I entered-1 :(");
    queryPath = "/home/akshay/Desktop/576_Pro/MediaServer/public/dataset/query";
    queryFolder = queryPath+'/'+req.param('query'); 
    console.log(queryFolder);
    console.log("I entered-2 :(");

    // exec("ba(sh ~/Desktop/576_Pro/MediaServer/public/run_project.sh",function(err, stdout, stderr){  
    console.log("I entered-3 :(");

    exec("bash ~/Desktop/576_Pro/MediaServer/public/run_project.sh "+queryFolder,function(error, stdout, stderr){
        if(error){
            console.log('Akshay');
            console.log('error'+error);
            return;
        } 

        console.log("Error "+stderr+"   stdout "+stdout);
        res.writeHead(302, {'Location': '/results'});
        res.end();

    });

我不知道,但我只是想知道我的bash文件是否没有进行node.js回调。这是run_project.sh bash文件,它包含在上面的代码中:

#!/bin/sh
echo "In Bash"
cd '/home/akshay/Desktop/576_Pro/MediaServer/public/python/'
echo "Convert query to mp4"
#./run_project2.sh $1
#python createpng.py -d $1 > supress.txt
echo "Converted to mp4"
echo "Started Color"
python color/Color_analysis.py -d $1 -c 1 > ../descriptors/color_temp.txt
python color/color_out.py ../descriptors/color_temp.txt > ../descriptors/color.txt
python color/color_result.py ../descriptors/color_temp.txt > ../descriptors/frame_info.txt
python color/color_graph.py ../descriptors/color_temp.txt > ../descriptors/graph_info.txt
echo "Finished Color"
# python color/color_check.py query_color.txt > color_out
echo "Started Audio"
python audio/Audio_Init.py
python audio/Audio.py $1 > ../descriptors/audio.txt
echo 'Finished Executing'
echo 'Started Motion'
python motion/back.py -d $1 > ../descriptors/video_desc_temp.txt
python motion/optical_check.py -d '/home/akshay/Desktop/576_Pro/MediaServer/public/descriptors/motion' -q ../descriptors/video_desc_temp.txt > ../descriptors/motion.txt 
echo 'Finished Video'

我在将它集成到node.js之前测试了bash脚本,并且没有遇到任何问题。它运行得非常好,除了事实上上面执行的python文件非常繁重并且需要花费大量时间这一事实需要大约5分钟。但除此之外,所有这些似乎都可行。

1 个答案:

答案 0 :(得分:0)

我不知道实际问题是什么。但我更改了bash脚本并将其分为三个不同的bash脚本。此外,我还针对三个不同的页面进行了路由,以完成整个过程,并在每个页面执行一个bash脚本。 node.js现在运行得很好,我相信问题必须是超时。