Board index » delphi » CreateProcess

CreateProcess

Hello, I'm calling ftp.exe on win2k with a CreateProcess(), and I pass Pipes
for StdOut, so I can read the output generated by ftp.exe . The problem is
that I only get a part of this output.

My calling command :
ftp -s:download\ftp.txt xxx.xxx.xxx.xxx
I replaced my IP address by xxx.xxx.xxx.xxx for the exemple

Exemple, if I call it from the Command Prompt, I get this :

Connected to xxx.xxx.xxx.xxx.
220 xxxx Microsoft FTP Service (Version 5.0).
User (xxx.xxx.xxx.xxx:(none)):
331 Anonymous access allowed, send identity (e-mail name) as password.

230 Anonymous user logged in.
ftp> ftp>
Local directory now blah\download.

ftp> lcd "download"
ftp> bye
221

Now there is the output I get from my program :
User (xxx.xxx.xxx.xxx:(none)): Local directory now blah\download.

lcd "download"
bye

This includes the 3 blanks lines!

There is my calling code :
  with SA do
  begin
   nLength := SizeOf(SA);
   bInheritHandle := True;
   lpSecurityDescriptor := nil;
  end;
  // create pipe for standard output redirection
  CreatePipe(StdOutPipeRead,  // read handle
            StdOutPipeWrite, // write handle
            @SA,             // security attributes
            0                // number of bytes reserved for pipe - 0
default
            );
  // create pipe for standard input redirection
  CreatePipe(StdInPipeRead,  // read handle
            StdInPipeWrite, // write handle
            @SA,             // security attributes
            0                // number of bytes reserved for pipe - 0
default
            );
  try
    // Make child process use StdOutPipeWrite as standard out,
    // and make sure it does not show on screen.
    with SI do
    begin
     FillChar(SI, SizeOf(SI), 0);
     cb := SizeOf(SI);
     dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
     wShowWindow := SW_HIDE;
     hStdInput := StdInPipeRead;
     hStdOutput := StdOutPipeWrite;
     hStdError := StdOutPipeWrite;
    end;

    // Create the process
    WasOK := CreateProcess(nil, PChar(p_file + ' ' + p_params), nil, nil,
True, 0, nil, nil, SI, PI);

and later I read in with :
       WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil);

Ok , I suspect ftp.exe writing some information in an other pipe. So how can
I read this pipe if it's the case and/or is there something not right in my
code that makes me miss a part of the output?

Thank you very much!!!

Etienne

 

Re:CreateProcess


Quote
Etienne Houle wrote:
> Hello, I'm calling ftp.exe on win2k with a CreateProcess(), and I pass Pipes
> for StdOut, so I can read the output generated by ftp.exe . The problem is
> that I only get a part of this output.

> My calling command :
> ftp -s:download\ftp.txt xxx.xxx.xxx.xxx
> I replaced my IP address by xxx.xxx.xxx.xxx for the exemple

> Exemple, if I call it from the Command Prompt, I get this :

> Connected to xxx.xxx.xxx.xxx.
> 220 xxxx Microsoft FTP Service (Version 5.0).
> User (xxx.xxx.xxx.xxx:(none)):

[snip]

Why are you doing it this way? Delphi comes with an FTP client
component, and there are others available to download.

These give you complete control of the FTP session.

--
jc

Re:CreateProcess


Im Artikel <ksIfa.2067$D24.222...@news20.bellglobal.com>, "Etienne Houle"
<ho...@irosoft.com> schreibt:

Quote
>Hello, I'm calling ftp.exe on win2k with a CreateProcess(), and I pass Pipes
>for StdOut, so I can read the output generated by ftp.exe . The problem is
>that I only get a part of this output.

Perhaps the missing output goes to stderr, not to stdout?

DoDi

Other Threads