Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a file handle for the redirection. That's what your cmd script does. That redirects to a file named <code>'MYDB.bak'</code>. </p> <p>So, call <code>CreateFile</code> to create a file with that name, and assign the handle returned as <code>StartupInfo.hStdOutput</code>. When the external process has finished, call <code>CloseHandle</code> on the file handle to close the file. You'll need to decide what to do about the standard error handle. One common choice is to merge it with standard output. Assign the same handle to both <code>hStdOutput</code> and <code>hStdError</code>.</p> <p>Your code is assigning standard handles, but not asking that the external process uses them. You need to include <code>STARTF_USESTDHANDLES</code> in <code>StartupInfo.dwFlags</code>.</p> <p>The call to <code>CreateFile</code> will look like this:</p> <pre><code>StdOutFileHandle := CreateFile( 'MYDB.bak', GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 ); </code></pre> <p>Check that the value returned by <code>CreateFile</code> is not equal to <code>INVALID_HANDLE_VALUE</code>.</p> <p>As I mentioned in your previous question, you need the external process to inherit the file handle that you pass it. If you don't allow inheritance of handles then the external process cannot use the handle that you pass it. So pass <code>True</code> for the <code>bInheritHandles</code> parameter of <code>CreateProcess</code>.</p> <p>The file handle created by <code>CreateFile</code> is not, by default inheritable. You can either pass security attributes that make it inheritable. Or you can set it explicitly after you have created. The latter looks like this:</p> <pre><code>Win32Check(SetHandleInformation(StdOutFileHandle, HANDLE_FLAG_INHERIT, 1)); </code></pre> <p>Examples of the former (in the context of pipes) can be seen in my answer here: <a href="https://stackoverflow.com/questions/19054789/how-to-redirect-binary-gbak-output-to-a-delphi-stream">How to redirect binary gbak output to a Delphi stream?</a></p> <p>The code that mentions <code>StdOutPipeWrite</code> all needs to be deleted. It cannot work at the moment because you are not initializing the handle.</p> <p>You should make good use of <code>try/finally</code> to ensure that you don't leak any handles even in the face of exceptions.</p> <p>Finally, your code contains a lot of errors, and little error checking. I suggest that you read and re-read the documentation for <code>CreateProcess</code>. Also have a good read of this example on MSDN: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/windows/desktop/ms682499.aspx</a>. Although it uses pipes, the principals are the same. Do exactly the same, but instead of pipes use the handle returned by the call to <code>CreateProcess</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload