Home > OS >  Run a Programm with C and go on
Run a Programm with C and go on

Time:10-15

Im wondering why my Programm pauses after executing a programm.

#include<unistd.h>
#include<stdio.h>

int main() {

    printf ("Welcome to the Programm\n");
    system ("\"C:\\Program Files (x86)\\StreamCompanion\\osu!StreamCompanion.exe\"");
    printf ("Hopefully that worked\n");
    sleep(5);
}

I successfully made it that it runs that Programm, Yes!

But it would not respond this message: Hopefully that worked

The Programm pauses in the Background until the executed Programm is closed!

after that the message goes out!

Thanks for ongoing Help! c:

CodePudding user response:

This is operating system specific. In Windows you can use ShellExecute to run the program without waiting for it to complete. If your application is exiting immediately after launching the other application, a short Sleep is sometimes required at the end.

#include <stdio.h>
#include <Windows.h>

int main() {

    printf("Welcome to the Programm\n");
    ShellExecuteA(
        NULL, NULL,
        "C:\\Program Files (x86)\\StreamCompanion\\osu!StreamCompanion.exe",
        NULL, NULL, SW_SHOW);
    printf("Hopefully that worked\n");
    Sleep(1000);
    return 0;
}

Use ShellExecuteW(..., L"C:\\Program Files (x86)\\StreamCompanion"...) for Unicode names.

  •  Tags:  
  • c
  • Related