0

have a problem with system("command"). I want to start .exe with some parameters but "B0 P1" cant be compiled because of use "" in command string. Any solution/tips :)?

int main() {
    system ("start C:\\PROGRA~2\\BEL\\Realterm\\realterm.exe FIRST=1 SENDSTR= "B0 P3" ");
}
2
  • Have you tried escaping them? How come you are not escaping the backslashes? Commented Apr 19, 2019 at 13:24
  • 4
    You can escape the quotes inside your string with a backslash. Commented Apr 19, 2019 at 13:24

1 Answer 1

3

You need to escape quote characters inside your string:

int main() {
    system ("start C:\\PROGRA~2\\BEL\\Realterm\\realterm.exe FIRST=1 SENDSTR= \"B0 P3\" ");
}

In c++ 11 you can also use string literal R"(...)" if you don't want to escape characters:

int main() {
    system ( R"(start C:\PROGRA~2\BEL\Realterm\realterm.exe FIRST=1 SENDSTR= "B0 P3")" );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.