1

For some reason I cannot fathom out how to append text to a text file already contating data I need

I have currently got the script just console.log my data.

casper.then(function() {
    if (this.exists('.srBtnRed')) {
        this.echo(casper.cli.get(0) + "|" + casper.cli.get(1) + " Up Impossible !!");
        this.exit();
    }
});

Can anybody edit the above code to save the result to the next clean line of results.txt

Also I do have require('fs') in my script .

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • possible duplicate of [Phantomjs append to file with fs.write](http://stackoverflow.com/questions/25631963/phantomjs-append-to-file-with-fs-write) – Artjom B. Jan 19 '15 at 13:22

1 Answers1

0

echo prints to the console, you are likely looking for filesystem module.

var fs = require('fs');
fs.write('results.txt', casper.cli.get(0) + "|" + casper.cli.get(1) + " Up Impossible !!", 'a');

Source

Source #2

Community
  • 1
  • 1
alandarev
  • 8,349
  • 2
  • 34
  • 43
  • this works in a fashion but it is not keeping the data its delting the data then adding the line can u help – terry toxica Jan 19 '15 at 12:44
  • 1
    Strange. the flag `'a'` in the end tells to open the file in *append mode*. Are you sure you did not accidently remove the flag? :) – alandarev Jan 19 '15 at 12:55
  • http://stackoverflow.com/a/25631964/1132711 - same solution, and is reported to be working. – alandarev Jan 19 '15 at 12:59