Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

930 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

14 Experts available now in Live!

Get 1:1 Help Now