Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

windows system call

hello,

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?

thanks
0
richardb_p
Asked:
richardb_p
1 Solution
 
AlexFMCommented:
Use CreateProcess function.
0
 
richardb_pAuthor Commented:
how is that cross platform?
0
 
grg99Commented:
Use the "start" command, it has an option for hiding the window.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jkrCommented:
>>how is that cross platform?

Like that:

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

   STARTUPINFO         si;
   PROCESS_INFORMATION pi;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

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

   bRes    =   CreateProcess   (   NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS,
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

   WaitForSingleObject (   pihProcess, INFINITE);

   GetExitCodeProcess  (   pi.hProcess,    &dwCode);

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

   return  (   dwCode);

#else

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

#endif
}
0
 
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.
0
 
jkrCommented:
>>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()'.
0
 
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.
0
 
jkrCommented:
>>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.

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now