0

I'm fairly new to casperjs (running on phantomjs) - I'm sure I'm probably missing a basic programming element here; looking to see if anyone has some insight. At the end of my script I call casper.exit(), which does exit the script and seemingly steps back into the current directory, however the current directory is not displayed in the command window.

I don't think it's related to the script itself and I can replicate with even the most basic scripts. Below is a screenshot of the outcome:

casperjs exit png

Where the yellow circle is after the .exit() call, and I would be expecting to see the cd (underlined in red)

I've tried using casper.die() with similar results.

Although it's not a big deal, it might be confusing to someone less familiar with casper/phantom and the script itself.. I guess I'm left with a few questions:

  1. Is this expected behavior from how phantomjs/casperjs is built?
  2. If not, is this a 'bad' thing? (affecting memory, stack, etc.)
  3. Is there a way to return to the CD using casper/phantom or some other method in the script itself?
  4. Bonus question.. is there a difference between using casper.die() and casper.exit()? I see that .die() logs a status message but other than that is there a preferred method to stop script execution or is it just syntactics, as in PHP ?
Community
  • 1
  • 1
twill
  • 755
  • 4
  • 15

1 Answers1

1

It is the normal behavior of the casperjs executable on windows. This has likely something to do with the python part of the executable since phantomjs does not have this behavior.

Another indicator is that when casperjs is run through phantomjs like described here, there is no such behavior and I get a normal prompt after exit.

I would say, this is a cosmetic problem that can throw you off when you first encounter it. This isn't really a problem.

Regarding the Bonus question: die can be seen as a fancier exit since it calls exit itself, but it is a more controlled way to exit casper. There is an optional message that is written to stout in red and an additional die event handler. die also sets the execution time of the script.

Community
  • 1
  • 1
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • Thanks.. that makes sense. I also did not see running phantom, which is why I thought I might have been doing something improperly. – twill Sep 16 '14 at 14:31
  • Added the bonus question answer. What do I get now? ;) – Artjom B. Sep 16 '14 at 14:44
  • [a buffalo nickel!](http://upload.wikimedia.org/wikipedia/commons/c/c3/Indian_Head_Buffalo_Reverse.png) – twill Sep 16 '14 at 15:00
  • found this around the web if anyone else comes across this: `die()` is just a shortcut for `echo()` then `exit()` – twill Sep 16 '14 at 16:14