Hi All,

I am using system function to invoke a jar file in MAC OS. But the jar file path has space in the folder name.

string arg1= "MyWindow";
	string jarFile = "java -jar /Users/User1/Desktop/Sample Java/Demo.jar ";
	jarFile += arg1;
	system(jarFile.c_str());

"/Sample Java" folder name has space in between. Because of which the jar is not coming up. How to to pass a path which has space in folder name to system function.

Try escaping some " " and putting them in your path, so it treats it as if the filename was in quotes at the prompt:
"java -jar \"/Users/User1/Desktop/Sample Java/Demo.jar\" ";

If not try"java -jar /Users/User1/Desktop/Sample%20Java/Demo.jar ";
but I'm not confident it will work (it will probably just insert the space all over again).

The first solution works.

Thanks a lot

Try escaping some " " and putting them in your path, so it treats it as if the filename was in quotes at the prompt:
"java -jar \"/Users/User1/Desktop/Sample Java/Demo.jar\" ";

If not try"java -jar /Users/User1/Desktop/Sample%20Java/Demo.jar ";
but I'm not confident it will work (it will probably just insert the space all over again).

It works for me too i just follow your work:
Syntax for c++ :

#include <windows.h>
int main ()
{
system("C:\\Junk\\Raptor\" Connector\\input.txt\"");
//	OR
system("C:\\Junk\\\"Raptor Connector\\input.txt\"");
  return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.