Ben Fortune
Ben Fortune

Reputation: 32117

Spawn child process escaping the quotes

I'm trying to add arguments which require the string to be quoted, but spawn is escaping them.

Code is as follows:

var printProc = spawn('RawPrintServer.exe', ['STANDALONE', '"RawPrinter"'], {
    detached: true,
    stdio: ['ignore', out, err]
});

When I check task manager, I can see that it has spawned it as

RawPrintServer.exe STANDALONE "\"RawPrinter\""

Whereas I need

RawPrintServer.exe STANDALONE "RawPrinter"

Upvotes: 0

Views: 1330

Answers (2)

tpower
tpower

Reputation: 56876

windowsVerbatimArguments

var printProc = spawn('RawPrintServer.exe', ['STANDALONE', '"RawPrinter"'], {
  detached: true,
  stdio: ['ignore', out, err],
  windowsVerbatimArguments: true
});

Found it mentioned on a bug (Quotes are not handled correctly when child_process.spawn() parses args) but I don't think it's documented.

Upvotes: 2

john Smith
john Smith

Reputation: 17906

looks like you need to change

['STANDALONE', '"RawPrinter"']

to

['STANDALONE', 'RawPrinter']

Upvotes: 2

Related Questions