Results 1 to 7 of 7

Thread: How command line prog with progress bar in form....

  1. #1

    How command line prog with progress bar in form....

    How can i do this :
    I have a function that runs and capture the a command line prog....

    here is the function
    Code:
    function RunCaptured(const _dirName, _exeName, _cmdLine, filename: string): Boolean;
    var
      start: TStartupInfo;
      procInfo: TProcessInformation;
      tmpName: string;
      tmp: Windows.THandle;
      tmpSec: TSecurityAttributes;
      res: TStringList;
      return: Cardinal;
    begin
      Result := False;
      try
        tmpName := 'Test.tmp';
        FillChar(tmpSec, SizeOf(tmpSec), #0);
        tmpSec.nLength := SizeOf(tmpSec);
        tmpSec.bInheritHandle := True;
        tmp := Windows.CreateFile(PChar(tmpName),
        Generic_Write, File_Share_Write,
        @tmpSec, Create_Always, File_Attribute_Normal, 0);
        try
        FillChar(start, SizeOf(start), #0);
        start.cb := SizeOf(start);
        start.hStdOutput := tmp;
        start.dwFlags := StartF_UseStdHandles or StartF_UseShowWindow;
        start.wShowWindow := SW_HIDE;
        // Start The Program
        if CreateProcess(nil, PChar(_exeName + ' ' + _cmdLine), nil, nil, True,
          0, nil, PChar(_dirName), start, procInfo) then
          begin
            Form1.pb1.Position := procInfo.hProcess;
            Application.ProcessMessages;
            SetPriorityClass(procInfo.hProcess, Idle_Priority_Class);
            WaitForSingleObject(procInfo.hProcess, Infinite);
            GetExitCodeProcess(procInfo.hProcess, return);
            Result := (return = 0);
            CloseHandle(procInfo.hThread);
            CloseHandle(procInfo.hProcess);
            Windows.CloseHandle(tmp);
            // Add the output
            res := TStringList.Create;
            try
              res.LoadFromFile(tmpName);
            finally
              res.Free;
            end;
            Windows.CopyFile(Pchar(tmpName),pchar(filename),FALSE);
            Windows.DeleteFile(PChar(tmpName));
          end
        else
          begin
           Application.MessageBox(PChar(SysErrorMessage(GetLastError())),
            'RunCaptured Error', MB_OK);
          end;
        except
          Windows.CloseHandle(tmp);
          Windows.DeleteFile(PChar(tmpName));
          raise;
        end;
      finally
      end;
    end;
    Now i want to put a progress bar in form and get the current position of the captured prog...
    How can i do that....

    Please help....
    Last edited by azrael11; 30-03-2011 at 12:42 PM.

  2. #2
    I don't know what you mean. Say you use RunCaptured() to start a game. How could the program predict how long he is going to play it? If it is some self made application you can print out some "tags" that you can use to synchronize with progressbar. Maybe App->App communication with system messages, sockets or files...

  3. #3
    Quote Originally Posted by User137 View Post
    I don't know what you mean. Say you use RunCaptured() to start a game. How could the program predict how long he is going to play it? If it is some self made application you can print out some "tags" that you can use to synchronize with progressbar. Maybe App->App communication with system messages, sockets or files...
    First thanks for the reply....
    No i mean that i run a command line exe that generate big text,xml,doc and other files....
    I want to know where in progress bar the progress of this generation is....

    example -> RunCaptured('d','program.exe','-createxml','bigxmlfile.xml');
    i execute this and i wait until its done...
    I simple want to know the progress of this execution....

    Thanks again....

  4. #4
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    if you know the number of lines to be processed and your current position then you could use something like this

    ProgressBar.Position:= 100 * currentline div totallines;

  5. #5
    Quote Originally Posted by Carver413 View Post
    if you know the number of lines to be processed and your current position then you could use something like this

    ProgressBar.Position:= 100 * currentline div totallines;
    That is the problem
    How can i know what the command line program reads and how can i count a command line execution file the last number so i can use it...

  6. #6
    Quote Originally Posted by azrael11 View Post
    That is the problem
    How can i know what the command line program reads and how can i count a command line execution file the last number so i can use it...
    program.exe has to tell your program what its progress is, like i mentioned in my last post. Whatever method you pick it will slow down the progress somewhat.

    I'd propably go with broadcasted Windows messages. You can read more details from msdn:
    SendMessage: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    GetMessage: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    General helpful link:
    http://www.google.fi/#sclient=psy&hl...cd37774a490ead

    If your program.exe is an application you haven't made yourself there is simply no way. Well... only hacking in it with dll injection or something and reading its memory space, but lets ignore that
    Last edited by User137; 01-04-2011 at 03:21 PM.

  7. #7
    Quote Originally Posted by User137 View Post
    program.exe has to tell your program what its progress is, like i mentioned in my last post. Whatever method you pick it will slow down the progress somewhat.

    I'd propably go with broadcasted Windows messages. You can read more details from msdn:
    SendMessage: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    GetMessage: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    General helpful link:
    http://www.google.fi/#sclient=psy&hl...cd37774a490ead
    Thanks my friend a lot of read....


    Quote Originally Posted by User137 View Post
    If your program.exe is an application you haven't made yourself there is simply no way. Well... only hacking in it with dll injection or something and reading its memory space, but lets ignore that
    Hmmmm.... let me think...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •