Solved

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

Posted on 2003-10-24
4
317 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
[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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Parsing XML instructions in Java/any other language.... 3 127
Dialogbox API leak? 18 118
maximize the sum of fractions 33 75
COM server issue 2 24
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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 clear a vector as well as how to detect empty vectors in C++.

734 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