开发者

CMD.exe quoting a string

What's the exact way to properly quote a single command line argument? For example, I have some random text in a variable $X. I need to quote it in a way so that if I call

system("program.exe " + $X_QUOTED);

then argv[1] of my program.exe has to match original unquoted $X

imagine I have this program.exe:

int main(const char **argv, int){ puts(argv[1]开发者_运维知识库); }

and the output of command: "program xxxx" is:

"test |test

what xxxx has to literally be? I tried to add quotes and all that trickery, but then I can always add some other type of output that would break my approach to quote cmd line arguments.


H:>args """test |test"
argv[0] = args
argv[1] = "test |test

Apparently:

  • Replace each quote by ""
  • Surround the argument with quotes
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜