windows system call


in my program I go system("some other program");
This works fine on Linux but on Windows a dialog box appears while it executes. What can I do to stop this appearing while remaining cross platform?

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

jkrConnect With a Mentor Commented:
>>how is that cross platform?

Like that:

DWORD ExecuteAndWaitForCompletion   (   char*   pszCmd)
#ifdef WIN32 // Windows, use 'CreateProcess()'

   STARTUPINFO         si;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

   si.cb           =   sizeof  (   STARTUPINFO);
   si.dwFlags      =   STARTF_USESHOWWINDOW;
   si.wShowWindow  =   SW_HIDE;

   bRes    =   CreateProcess   (   NULL,

   WaitForSingleObject (   pihProcess, INFINITE);

   GetExitCodeProcess  (   pi.hProcess,    &dwCode);

   CloseHandle (   pi.hProcess);
   CloseHandle (   pi.hThread);

   return  (   dwCode);


   return system ( pszCmd); // not Windows, use 'system()'

Use CreateProcess function.
richardb_pAuthor Commented:
how is that cross platform?
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Use the "start" command, it has an option for hiding the window.

richardb_pAuthor Commented:
grg99: where can I find information on the start command?

jkr: thanks, that will be my last resort. But system calls are pretty standard functionality so is there some kind of wrapper to do this?

I was expecting there would be a way to just disable/hide the terminal on windows so I could still use system(). I can get rid of the default console by compiling with -mwindows.
>>But system calls are pretty standard functionality

... with all the side effects. 'system()'. IMO not a good idea to rely on it, since there is no guaranteed integration in the OS. I'd always use it as a last resort, even on UN*X there are APIs that I'd way prefer over 'system()'.
richardb_pAuthor Commented:
yeah I don't feel comfortable either, unfortuantely not my choice. I have to execute a compiled program (contents unknown to me) with different argument combinations and halt while it executes. This is fine on Debian and Solaris but Windows flashes that damn terminal. I'll give you the points jkr unless something comes up quickly.
>>I have to execute a compiled program (contents unknown to me) with different argument combinations and
>>halt while it executes.

That's excactly what 'ExecuteAndWaitForCompletion()' does.

All Courses

From novice to tech pro — start learning today.