-1

I want to open a .jar file when a button is clicked in Windows. I have the following code:

private: System::Void btnStartServer_Click(System::Object^  sender, System::EventArgs^  e) {
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    int spi=sizeof(pi);
    int ssi= sizeof(si);
    ZeroMemory( &si, sizeof(si) );
    si.cb=sizeof(STARTUPINFO); //sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    char b = 0;
    b = CreateProcess("C:\\Program Files\\Java\\jre7\\bin\\java.exe ", "-jar craftbukkit.jar", NULL, NULL, 0, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);

    btnStartServer->Text = String::Format(L"{0}", b);
}

But when I press the button the button's text changes to "1", but I don't see any proccess called "java" in Task Menager.

If you know how to open, read output and give input to/from a .jar file, I'd appreciate if you answered: How To Open, Read Output and Give Input To a .jar file with C++?.

Any help would be appreciated.

Community
  • 1
  • 1
davidweitzenfeld
  • 1,021
  • 2
  • 15
  • 38

1 Answers1

0

I managed to fix it finally! I just had to add something to the second argument of CreateProcess:

b = CreateProcess("C:\\Program Files\\Java\\jre7\\bin\\java.exe ", "java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true", NULL, NULL, 0, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
davidweitzenfeld
  • 1,021
  • 2
  • 15
  • 38