Solved

windows system call

Posted on 2006-10-27
8
282 Views
Last Modified: 2010-08-05
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
Comment
Question by:richardb_p
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 17824678
Use CreateProcess function.
0
 

Author Comment

by:richardb_p
ID: 17825265
how is that cross platform?
0
 
LVL 22

Expert Comment

by:grg99
ID: 17825494
Use the "start" command, it has an option for hiding the window.

0
Independent Software Vendors: 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!

 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 17826034
>>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
 

Author Comment

by:richardb_p
ID: 17827301
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
 
LVL 86

Expert Comment

by:jkr
ID: 17827611
>>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
 

Author Comment

by:richardb_p
ID: 17832937
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
 
LVL 86

Expert Comment

by:jkr
ID: 17844002
>>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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question