Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

windows system call

Posted on 2006-10-27
8
Medium Priority
?
284 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Accepted Solution

by:
jkr earned 1000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

715 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