Search code examples
javascriptphantomjscasperjs

Javascript does not stop running


I´ve got the problem, that this little js does not stop to run... Or i say it better like, he stops, but does not exit.

function main(){
if(laenge<=1){
    alert("exit");
    return;}
var fs = require('fs');var i=0;
var all = fs.open('acc_all.txt', 'r');
var laenge = 25999;
while(!all.atEnd()){
    var line = all.readLine();
    console.log(line+" + "+laenge);
    i++;laenge--;
}
all.close();
}
main();

It looks like this ... Console screen


Solution

  • You need to add phantom.exit() at the end of your main function.

    You can set the debug flag to true to see additional information:

    phantomjs --debug=true index.js
    

    You might notice that when calling phantom.exit() it'll exit, but there is a 4 second delay. This is a known issue when there is an active network connection.

    https://github.com/ariya/phantomjs/issues/14033