Seti Net
Seti Net

Reputation: 743

How to ShellExecute a program AND THEN send it command line text

I can open an external program fine with ShellExec

 ret := ShellExecute(handle, 'open', PChar(filename), nil, nil, SW_NORMAL);

but then I would like to send it commands like:

msg := 'open ftp://MyUser:[email protected]';

Is this possible?

Upvotes: 1

Views: 1245

Answers (1)

David Heffernan
David Heffernan

Reputation: 613572

It's possible I guess, but it's not the best way to do this. The best way is to use CreateProcess. It's a more involved API, but it will make what you are attempting simpler.

The procedure goes like this:

  1. Create one or two pipes. You need one for the child's standard input. You need another if you wish to capture its output.
  2. Call CreateProcess to create the child. Attach the read end of the first pipe to the child's standard in. Attach the write end of the second pipe to the child's standard output.
  3. When you wish to send commands, write to the first pipe. When you wish to read output, read from the second pipe.

This can be daunting if you are not familiar with such coding. You might do well to find a library that makes it easy.

This MSDN article demonstrates how:

Creating a Child Process with Redirected Input and Output

Since you seem to be wanting to do FTP, you'd be better off avoiding an external process. Use a library such as Indy.

Upvotes: 3

Related Questions