npm / node-which

Like which(1) unix command. Find the first instance of an executable in the PATH.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Windows friendly?

azat-co opened this issue · comments

Is it windows friendly?

I got reports that it didn't work right out of the box for the windows paths with spaces, e.g., "Program Files/..."

This is the proposed work around:

    var node
    node = which.sync('node')
    // Surrounds with double quotes if path contains a space
    if (node.indexOf(' ') != -1) {
      node = '"' + node + '"'
    }

If needed, I can submit a PR.

Well, if the path includes spaces, then which will return a string with spaces in it.

How you use that string is up to you. In some cases, yo'ull have to quote it, and in others you won't. For example, child_process.spawn('C:\\Program Files\\node.exe', [someFilename]) will work just fine. But if you pass that to child_process.exec() then you might need to quote it.

It's outside the scope of this module to add quotes. It does pass its tests on Windows, though I don't dev on Windows primarily and so it probably doesn't get tested as frequently.

@isaacs It makes sense. Thanks.