🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #12689

Re: ShellExecute Error

#12689
From: Remy Lebeau (TeamB)
Date: Fri, 21 Nov 2003 00:13
62 lines
3004 bytes
"George" <george@nospam.org> wrote in message
news:3fbd535a@newsgroups.borland.com...
> Well the file is c:\\ ... i wrote C:\ in the newsgroups only.

Please *always* copy/paste your actual code as-is, never type it by hand.
That is too error-prone, and can lead to conflicting information.

> Can you please give me an example of this code in CreateProcess?

(untested, and error handler omitted for simplicity)

    HANDLE hFile = CreateFile("c:\\output.txt", GENERIC_READ |
GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
NULL);

    HANDLE hReadPipe = NULL;
    HANDLE hWritePipe = NULL;
    CreatePipe(&hReadPipe, &hWritePipe, NULL, 0);

    STARTUPINFO si = {sizeof(STARTUPINFO), 0} ;
    PROCESS_INFORMATION pi = {0};

    si.dwFlags = STARTF_USESTDHANDLES;
    si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
    si.hStdOutput = hWritePipe;
    si.hStdError = hWritePipe;

    if( CreateProcess(NULL,
"c:\\mysqldump.exe --user=root --password=pass --database=data1",
            NULL, NULL, TRUE, 0, NULL, "c:\\", &si, &pi) )
    {
        BYTE buffer[1024];
        DWORD ProcRes = STILL_ACTIVE;

        while( ProcRes == STILL_ACTIVE )
        {
            DWORD dwRead = 0, dwWritten = 0;
            if( ReadFile(hReadPipe, buffer, 1024, &dwRead, NULL) )
                WriteFile(hFile, buffer, dwRead, &dwWritten, NULL);

            GetExitCodeProcess(pi.hProcess, &ProcRes);
            Application->ProcessMessages();
        }

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

    CloseHandle(hReadPipe);
    CloseHandle(hWritePipe);
    CloseHandle(hFile);

> I can't make it work to wait until finish.

CreateProcess() returns the process handle just like ShellExecuteEx() can,
so your current loop to wait until the process finishes should still work
fine.  Alternatively, use WaitForSingleObject() instead of
GetExitCodeProcess().


Gambit
Technical Details
Message-ID: <3fbd57b8$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3fbd4eec$1@newsgroups.borland.com> <3fbd525b$1@newsgroups.borland.com> <3fbd535a@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,9b656969a1fc70df
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-11-20 16:40:56 PST
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3fbd4eec$1@newsgroups.borland.com> <3fbd525b$1@newsgroups.borland.com> <3fbd535a@newsgroups.borland.com>
Subject: Re: ShellExecute Error
Date: Thu, 20 Nov 2003 16:13:19 -0800
Lines: 64
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 67.22.137.149
Message-ID: <3fbd57b8$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1069373368 67.22.137.149 (20 Nov 2003 16:09:28 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail