-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
How to trim quotation for argv #13
Comments
Normally the quotes get removed as part of the shell processing and do not appear in I see this with zsh as the shell. // build.js
console.log(process.argv[2])
const argv = require('minimist')(process.argv.slice(2))
console.log(argv.foo) % node build.js --foo=abc
--foo=abc
abc
% node build.js --foo="abc"
--foo=abc
abc
% echo --foo="abc"
--foo=abc |
( |
"how the program is called" is in the OP, but the real question is, what shell/OS are you using? |
HI all and thanks for your response. It really doesn't run in a normal shell environment. Here is the reproduction code: // main.go
// you can write it with your own nodejs code
package main
import (
"context"
"os"
"os/exec"
)
func main() {
cmd := exec.CommandContext(context.Background(), "C:\\Windows\\System32\\cmd.exe", "--%", "/c", `node test.js --foo="bar"`)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
if err := cmd.Start(); err != nil {
panic(err)
}
cmd.Wait()
} // test.js
const argv = require('minimist')(process.argv.slice(2))
console.log(argv)
// actuly
console.log(argv.foo === '"bar"') // true
// expect
console.log(argv.foo === 'bar') // false
console.log('value', argv.foo) Run the program$ go run main.go
true
false
value "bar" NoteBefore use minimist, I use the const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv
// actuly
console.log(argv.foo === '"bar"') // false
// expect
console.log(argv.foo === 'bar') // true
console.log('value', argv.foo) process.argv[
'C:\\Program Files\\nodejs\\node.exe',
'C:\\Users\\Admin\\test.js',
'--foo="bar"'
] |
That still suggests a bug in go’s shell exec stuff to me; yargs may have worked around it tho. |
Yargs does have some extra handling for quotes which might be why it worked. I was able to reproduce the quoted argument problem on the command-line with So I also think your issue is introduced with the e.g. In summary, not looking like a problem with minimist. |
Closing, but we can certainly reopen if there's something actionable for minimist. |
node script/build.js --foo="bar"
The text was updated successfully, but these errors were encountered: