1

argc parameter in main function doesn't include redirection command [<, >], but I faced a confusing problem when using a double quote:

  • Shell: CMD
    • I expected argc is 3 and Yes!:
      a.exe aa bb < input.txt
      

    • I expected argc is also 3 , but 5, as I want to input double quote as argument:
      a.exe \" bb < input.txt
      
JW0914
  • 7,865
Doge
  • 11
  • (1) What if you used ^"? (2) What is a.exe? (3) Do you know what _setargv() this a.exe uses? What is it? – Kamil Maciorowski Feb 07 '24 at 13:30
  • (1)argc is 2 and argv[1] is empty . (2)a.exe is simple program, print agrc. (3) i dont know that. i dont use it my code. – Doge Feb 07 '24 at 13:41
  • I don't know if it's still the case in Windows 11, but earlier in the Windows world even a "simple program" could impose its own syntax by providing or choosing _setargv(). See the second part of this answer. I don't expect the situation has changed, so probably it's totally up to a.exe (i.e. up to _setargv() it uses), how exactly it splits the string you give it to an array of arguments, how it interprets quotes and escape characters, and what quotes and escape characters. – Kamil Maciorowski Feb 07 '24 at 13:49
  • I would try "^"". – harrymc Feb 07 '24 at 14:22
  • @KamilMaciorowski: A program can choose between the two: Either handle the command-line as one string, or use argc as broken into tokens by the standard library. – harrymc Feb 07 '24 at 14:25

0 Answers0