Solved

windows system call

Posted on 2006-10-27
8
276 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
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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now