0

I have installed Python on my PC (Windows 7) in order to implement tests for a Node application using casperjs. I want to be able to launch a casperjs from Node.

I have implemented a spawn child in Node:

var spawn = require('child_process').spawn;

var bin = "casper.cmd";
var args = [''];
var cspr = spawn(bin, args, {stdio: 'inherit'});

cspr.on('exit', function (code) {
    console.log('child process exited with code ' + code);
    process.exit(code);
});

In the same directory, I have implement the casper.cmd file:

casperjs casper_test.js

My casper test is the following:

var casper = require('casper').create();

casper.start('http://google.com/', function() {
    this.echo(this.getTitle(), 'INFO');
});

casper.run();

When I launch the first file with Node, I get:

C:\... ...\_test>casperjs casper_test.js 
'python' is not recognized as an internal or external command,
operable program or batch file.
child process exited with code 1

When I open a command line window and type python, it works. Hence, it means the PATH environment variable has been set properly.

How can I solve this issue?

Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453

1 Answers1

1

Solution was to update my PATH in the .cmd file:

set PATH=%PATH%;C:\Program Files\Python27;
casperjs casper_test.js
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
  • I had the same problem. I tried this and it didn't work. My solution was to actually reopen visual studio code. I believe it might have been the case too for Jerome. – mvoelcker Apr 23 '21 at 21:38