Pass \ in command line arguments of C++ - 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

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.

Delete all lines upto some regex match

I want to delete everything from start of the document upto some regex match, such as _tmm. I wrote the following custom command:
command! FilterTmm exe 'g/^_tmm\\>/,/^$/mo$' | norm /_tmm<CR> | :0,-1 d
This doesn't work as expected. But when I execute these commands directly using the command line, they work.
Do you have any alternative suggestions to accomplish this job using custom commands?
It seems that you want to remove from beginning to the line above the matched line.
/pattern could have offset option. like /pattern/{offset}, :h / for detail, for your needs, you could do (no matter where your cursor is):
ggd/_tmm/-1<cr>
EDIT
I read your question twice, it seems that you want to do it in a single command line.
Your script has problem, normal doesn't support |, that is, it must be the last command.
try this line, if it works for you:
exe 'norm gg'|/_tmm/-1|0,.d

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.

Badly placed ()'s error

Hello I'm using c++ with embedded SQL trying to receive command line arguments as SQL statements.
For instance I want to be able to do: ./a.out proceedings(foo#bar) and tokenize the argument into: proceedings, foo, and bar with #, (, and ) as delimiters.
Anyways, I was just wondering if there is a way to use brackets in the argument because I receive Badly placed ()'s as an error.
Nevermind, I've learned that I can use quotation marks in the command line which wont give me the error.

Devenv.exe with /I and whitespacess

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 (").