Devenv.exe with /I and whitespacess - c++

I've tried to compile an application with Directx. But this causes an PRJ0030 error for $().
How can I escape critical characters like (,) or blanks. Refering to the cmd I've used ^ but it does not help.

AdditionalLibraryDirectories=""$(DIRECTX_ROOT)\Lib\x86""
&quot should not be there. $(DIRECTX_ROOT) requires the macro to be set in a project property sheet. You are better off spelling it out:
AdditionalLibraryDirectories="c:\blah\dx9\Lib\x86"

cmd.exe unfortunately isn't a proper shell like bash, and parsing the command line is up to each individual program. I can't speak for devenv.exe but a common convention is to surround troublesome strings with double quotes (").

Related

Detecting semicolon as command line argument in linux

I am trying to run a C++ application where I am passing some command line arguments to it as follows:
./startServer -ip 10.78.242.4 tcpip{ldap=no;port=2435}
The application is getting crashed because it is not able to get the correct port. Searching over the web, I found that ";" is treated an end of command character (Semicolon on command line in linux) so everything after that is getting ignored. I also understand the putting it inside the quotes will work fine. However, I do not want to force this restriction of putting the arguments in the quotes on the users. So, I want to know is there a way I can process the ";" character with the argv array?
The semicolon separates two commands so your command line is equivalent to
./startServer -ip 10.78.242.4 tcpip{ldap=no
port=2435}
Your application will never know anything about either the semi colon or the second command, these will be completely handled by the shell. You need to escape the colon with a back slash or enclose it in quotes. Other characters which may cause similar issues include: $,\-#`'":*?()&|
Complex strings are much easier to pass either from a file or through stdin.
You need to quote not only the ; but in the general case also the { and }:
./startServer -ip 10.78.242.4 'tcpip{ldap=no;port=2435}'
If your users are required to type in that complicated last argument, then they can also be made to quote it.

Escaping in Visual Studio debugging command arguments

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?
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.

Pass \ in command line arguments of C++

I am working on a C++ program where one of the command line arguments needs to be a passed a regex. For example: abc.exe --option ab\[0\]
When I access the option value from inside the program, it becomes ab\\[0\\] which becomes a different regex.
Inside the program when I try to replace \\[ with \[ using boost::replace_all, the result is [ which also is not the intended output for me.
So, any suggestions on how to pass and retain \[ this while passing it through command line arguments
You can quote the parameter:
abc.exe --option "ab\[0\]"
Or use the shell escape sequence:
abc.exe --option ab\\[0\\]
Did you try these?
It was a problem with how visual studio displays the symbol. When I looked on the ASCII code of the symbol, it was alright. Thanks #ScottK for helping me to debug this through your comments

How do I open a file within notepad++ with C++?

I'm trying to get my c++ program to open an sql file in notepad++. I can get it to open with notepad like this:
system("notepad.exe script_foo.sql");
But that's undesirable as it's not formatted. When I try to substitute notepad.exe for notepad++.exe like this:
system("'C:\Program Files\Notepad++\notepad++.exe' script_foo.sql");
I get a invalid syntax error.
Any issues where I'm going wrong?
The WinNT shell uses double-quotes to include spaces in a file name. Single quotes are not recognized. So you need
"C:\Program Files\Notepad++\notepad++.exe" script_foo.sql
as your command.
To embed this in C++ source code, you'll need to escape backslashes (as Andre already mentioned) and also the double-quotes.
system("\"C:\\Program Files\\Notepad++\\notepad++.exe\" script_foo.sql");
In C++, the backslash character \ is an escape character in strings. You need to double the backslashes to achieve what you really want:
system("'C:\\Program Files\\Notepad++\\notepad++.exe' script_foo.sql");

C++ on Windows: executable path with whitespace in system() call

I am trying to execute a file with parameters using the "system()" function in C++ on Windows, and it works as long as there are no whitespaces in the filename. For parameters, putting double quotes around the string works, but when I try the same with the executable itself, I get the following error:
"the filename,directory name, or volume label syntax is incorrect"
Does anyone know how to handle this correctly?
Use a string like this:
cmd /S /C "your entire command line string"
See: How do I deal with quote characters when using cmd.exe
It should work, look for the problem elsewhere.
Perhaps something in your flow is removing the whitespace or the double quotes from the string.