0

In my c# console application, which takes string as arguments, I have a context menu item for images, that calls "myexe.exe %1", so path to file becomes argument for application. Even if path to file contains spaces, when I watch, what argument my application takes, I can see something like "VISUAL~3/...." (it is example when path to file contains "visual stuido", it has space).

But my application should understand how many arguments are given, so if it is called from context menu, everything is ok, because result argument has no spaces.

But I need call exe file from other application and give string arguments with spaces too. When I just give argument with spaces, my application splits it, so I don't know how to code spaces in argument to give it to exe file, like context menu does. How to do it?

2 Answers 2

1

You should double quote your command lines arguments, e.g.,

string args = "\"arg 1\" \"arg 2\"";
Sign up to request clarification or add additional context in comments.

2 Comments

it is not absolutely that I wanted, but I changed my code, so it is solved, thank you
@user1495756 - If this isn't what you wanted, why did you accept it as the answer, that makes no sense.
0

Both, the Path AND the Variable must be quoted separately, e.g., "myexe.exe" "%1". That will prevent an argument with spaces to produce an invalid path:

"myexe.exe %1" becomes "myexe.exe ar gu ment", an " executable that makes no sense ", while

"myexe.exe" "%1" becomes "myexe.exe" "ar gu ment", an " executable " " with a single argument ".

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.