@@ -75,6 +75,9 @@ function Rsync(config) {
7575
7676 this . _cwd = process . cwd ( ) ;
7777
78+ // Allow child_process.spawn env overriding
79+ this . _env = process . env ;
80+
7881 // Debug parameter
7982 this . _debug = hasOP ( config , 'debug' ) ? config . debug : false ;
8083}
@@ -428,6 +431,24 @@ Rsync.prototype.cwd = function(cwd) {
428431 return this . _cwd ;
429432} ;
430433
434+ /**
435+ * Get and set rsync process environment variables
436+ *
437+ * @param {string } env= Environment variables
438+ * @return {string } Return current _env.
439+ */
440+ Rsync . prototype . env = function ( env ) {
441+ if ( arguments . length > 0 ) {
442+ if ( typeof env !== 'object' ) {
443+ throw new Error ( 'Environment should be an object' ) ;
444+ }
445+
446+ this . _env = env ;
447+ }
448+
449+ return this . _env ;
450+ } ;
451+
431452/**
432453 * Register an output handlers for the commands stdout and stderr streams.
433454 * These functions will be called once data is streamed on one of the output buffers
@@ -479,11 +500,11 @@ Rsync.prototype.execute = function(callback, stdoutHandler, stderrHandler) {
479500 var cmdProc ;
480501 if ( 'win32' === process . platform ) {
481502 cmdProc = spawn ( 'cmd.exe' , [ '/s' , '/c' , '"' + this . command ( ) + '"' ] ,
482- { stdio : 'pipe' , windowsVerbatimArguments : true , cwd : this . _cwd } ) ;
503+ { stdio : 'pipe' , windowsVerbatimArguments : true , cwd : this . _cwd , env : this . _env } ) ;
483504 }
484505 else {
485506 cmdProc = spawn ( this . _executableShell , [ '-c' , this . command ( ) ] ,
486- { stdio : 'pipe' , cwd : this . _cwd } ) ;
507+ { stdio : 'pipe' , cwd : this . _cwd , env : this . _env } ) ;
487508 }
488509
489510 // Capture stdout and stderr if there are output handlers configured
0 commit comments