简体   繁体   中英

How to run java class via shellexecute (visual studio c++/mfc)

I want to run a java application via ShellExecute .

My Attempt:

ShellExecute(
              NULL, 
              NULL, 
              _T("cmd.exe"), 
              _T("/k C:\\Program Files\\Java\\jre1.8.0_45\\bin\\java -cp    C:\\Users\\aGer\\workspace\\IEC60870\\bin main.CApp 127.0.0.1 -p 2404"), 
              NULL, 
              SW_SHOWNORMAL
);

But this command yield an error:

The command "C:\\Program" is either written wrong or could not be found

Why?

由于命令行中两个单独的参数之间存在空格,因此需要引用路径。

For those who are searching for a solution. Just simply add \\" ..path..\\" , ie:

ShellExecute( NULL, NULL, _T("cmd.exe"), _T("/k \\"C:\\\\Program Files\\\\Java\\\\jre1.8.0_45\\\\bin\\\\java\\" -cp C:\\\\Users\\\\aGer\\\\workspace\\\\IEC60870\\\\bin main.CApp 127.0.0.1 -p 2404"), NULL, SW_SHOWNORMAL );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM