rk6010
rk6010

Reputation: 23

How to run a file in a specified program through c++

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.

Upvotes: 2

Views: 301

Answers (1)

Violet Giraffe
Violet Giraffe

Reputation: 33605

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.

Upvotes: 1

Related Questions