Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling child_process.spawn parameter "windowsVerbatimArguments" #17

Open
rebrec opened this issue Dec 26, 2019 · 0 comments
Open

Handling child_process.spawn parameter "windowsVerbatimArguments" #17

rebrec opened this issue Dec 26, 2019 · 0 comments

Comments

@rebrec
Copy link

rebrec commented Dec 26, 2019

Hi and thanks for this great package which works perfectly for me when running powershell or cmd processes under Windows.

I am getting troubles when trying to run powershell with command line parameters.
It seems that by default, the spawn method sanitize arguments.

So, for instance, if i try to run the following code :

const { platform } = require('os');
const path = require('path');

const Promise = require('promise');
const StatefulProcessCommandProxy = require("stateful-process-command-proxy");

const processCommand = 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'
const processArgs = ['-NoProfile', '-ExecutionPolicy bypass']


const statefulProcessCommandProxy = new StatefulProcessCommandProxy(
{
  name: "powershell",
  max: 5,
  min: 5,
  idleTimeoutMS: 10000,

  logFunction: function(severity,origin,msg) {
    console.log('                ' + severity.toUpperCase() + " " +origin+" "+ msg);
  },

  processCommand: processCommand,
  processArgs:  processArgs,
  processRetainMaxCmdHistory : 50,

  processInvalidateOnRegex :
    {
      'any':[{regex:'.*error.*',flags:'ig'}],
      'stdout':[{regex:'.*error.*',flags:'ig'}],
      'stderr':[{regex:'.*error.*',flags:'ig'}]
    },

  processCwd : path.join('.', '.'),
  processEnvMap : null,
  processUid : null,
  processGid : null,

  initCommands: null,

  validateFunction: (processProxy) => {processProxy.isValid()},
  preDestroyCommands: null
});

The powershell command which get executed is :

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile "-ExecutionPolicy bypass"

Which return an error (Notice the double quotes on the line above which should not be present).

When modifying the following code within processProxy.js, at line 179 :

this._processOptions['windowsVerbatimArguments'] = true;

Powershell start properly with the following command line :

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy bypass

Could you handle a parameter so that we can (on win32 platform) handle the spawn parameter windowsVerbatimArguments ?

I can try to do a pull request if you whish.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant