Solved

How can I run multiple commands a one time and hide the cmd window?

Posted on 2003-10-24
4
311 Views
Last Modified: 2010-04-01
How can I run this command mutiple times in a loop without waiting for the previous command to complete.  And how do I hide the cmd window?

findfile = FindFirstFile("*.*",&finddata);
    while(FindNextFile(findfile,&finddata))
    {
       if((finddata.dwFileAttributes!=FILE_ATTRIBUTE_DIRECTORY) && (strcmp(finddata.cFileName,"..")!=0) && (strcmp(finddata.cFileName,".")!=0))
       {
                  strcpy(fileName,finddata.cFileName);

                        strcpy(command,engine);
                        strcat(command, optionFilePath);
                        strcat(command, "\\");
                        strcat(command,fileName);
                        strcat(command, "\"");
                  
                        SetCurrentDirectory(djEnginePath);

                        system(command);
                        
                        SetCurrentDirectory(optionFilePath);


                  MoveOptionFile(archivedPath, fileName);
       }
    }
      FindClose ( findfile);
0
Comment
Question by:RowdyOne078
  • 2
4 Comments
 
LVL 8

Assisted Solution

by:mnashadka
mnashadka earned 250 total points
ID: 9614474
If you don't need to wait for the process to execute, you can use CreateProcess to create a process and not wait for the results:
STARTUPINFO si;
si.cb = sizeof si;
PROCESS_INFORMATION pi;
CreateProcess(NULL, command, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, directory, &si, &pi);

If you need to know when the processes are done, you can use WaitForSingleObject or WaitForMultipleObjects with the hProcess HANDLE that's returned in the PROCESS_INFORMATION struct (pi in my example).  Good luck.
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 9614543
You could use

DWORD ExecuteAsyncHidden   (   LPSTR   pszCmd)
{
   STARTUPINFO         si;
   PROCESS_INFORMATION pi;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   MSG                 msg;

   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
                               );

   GetExitCodeProcess  (   pi.hProcess,    &dwCode);

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

   return  (   dwCode);
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 9614551
Oops, remove the line

GetExitCodeProcess  (   pi.hProcess,    &dwCode);

:o)
0
 

Author Comment

by:RowdyOne078
ID: 9614701
thank you very much
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

744 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

11 Experts available now in Live!

Get 1:1 Help Now