2

I am trying to use the ShellExecute command for launching a program and open a file through a c++ code. I have included windows.h. The code I am writing is as follows:

ShellExecute(GetDesktopWindow(), "open", "C:\\Program Files (x86)\\EMSO\\bin\\emso.exe","C:\\Program Files (x86)\\EMSO\\bin\\MultiCSTR_Reaction.mso", NULL, SW_SHOWNORMAL);

The code opens the executable file but is not able to open the .mso file. It generates dialog boxes saying- 'File 'C:\Program' not found', 'File 'Files' not found' and 'File '(x86)\EMSO\bin\MultiCSTR_Reaction.mso' not found.' I can open the file through the command line. But how to open through a c++ code.

1 Answer 1

1

Try the path to a file (4th argument to ShellExecute) as follows:

"\"C:\\Program Files (x86)\\EMSO\\bin\\MultiCSTR_Reaction.mso\""

Programs can take multiple command line arguments separated by spaces. So, if you try to pass a string that contain spaces as an argument, you'll find it split into as many arguments as many spaces there are. To avoid this, the string needs to be surrounded by quotes.

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

1 Comment

@Violet you could maybe explain why you added the quotations (spaces in the path), for clarity.

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.