3

I'm trying to pass a command-line argument < (single angle bracket, without quotes) to a C++ program during a debugging session in Visual Studio. As described in Project settings for a C++ debug configuration, < has special meaning as a redirection operator, but it does not specify how to escape it. I've tried using "<" and ^<, but none of them do what I want. Invoking the command from command line with the "<" argument works as expected.

So it looks like debugging command arguments are preprocessed first. Is there any way to escape a character from this preprocessing?

5
  • Please give the complete command line that you want to use ("<", nothing else? this works for me) and the visual Studio Version that you are using. Commented Dec 27, 2017 at 12:29
  • < works because it's not an argument, it's a redirect operator. It won't actually pass an argument to your executable. As I stated in the question, I want to pass a single argument - the < string. Commented Dec 27, 2017 at 15:49
  • As I said: it works for me. When I enter "<" (with the double quotes), then the "<" (without double quotes) is passed to my program. So as I asked for, please give more information. Commented Dec 28, 2017 at 8:22
  • Sorry, my bad. I figured this out, see my answer. Thanks! Commented Dec 28, 2017 at 11:44
  • For those brought here by a search engine, I think there is a genuine issue here: code.visualstudio.com/docs/cpp/launch-json-reference says “If you are escaping characters, you will need to double escape them. For example, ["{\\\"arg1\\\": true}"] will send {"arg1": true} to your application.” But note that its example is either triple escaping (which I hadn’t tried), or single escaping of both the backslash and quote. Neither single, double, nor triple escaping worked for me. Commented Mar 27, 2020 at 22:58

1 Answer 1

3

Seems like passing "<" works if "Start debugging" is used. I was using "Start Without Debugging", so the problem can be reproduced by passing "<" to an empty console application and invoking "Start Without Debugging".

"Start Without Debugging" seems to actually invoke cmd.exe, so command arguments are subject to command line interpretation rules. The question then turns out to be really how to escape < in a command line. < outside double quotes can be escaped by using ^<, but I still have no idea how to escape < inside double quotes.

I must say it's somewhat surprising that interpretation of debugging command arguments is subject to different rules depending on how the program is started.

Sign up to request clarification or add additional context in comments.

2 Comments

Very interesting. I can reproduce that here, but have no solution. It would be good to ask the question on the MS community site (and maybe re-post an answer here).
@Igor Akhmetov, Thanks for sharing your solution here, if possible, you could mark it as the answer. In addition, we also get the same result as yours using "start without debugging(Ctrl+F5)" and "Start debugging(F5)". For this issue, like Werner Henze suggestion, you could report it to the community site: developercommunity.visualstudio.com/spaces/8/index.html. Thanks for sharing your solution again. Have a nice day:)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.