Solved

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

Posted on 2003-10-24
4
313 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

773 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