views:

155

answers:

2

System(); is able to call a program in PATH. How is it possible to send stdin read from e.g. a text field on a GUI to a command line program such as ftp, sftp ... with their own prompts?
System() waits for a program to quit, but ftp does not without user interaction. It's also not possible to create a batch file since it's read only one time in runtime, on start.

If possible, please write the solution in C for UNIX, if not in any other language.

+2  A: 

It is possible, but not all that easy. You might take a look at Expect. It is a programming language that automates the interaction with non-gui tools. The Expect library has been embedded in other things like Python so I would think you could embed it into your code in C.

Philip Schlump
+1  A: 

The easiest way I know is to use forkpty() with exec(). forkpty() returns a file descriptor which is redirected to the programs stdin and stdout. Whatever is written to the file descriptor is the input of the program. Whatever is written by the program can be read from the file descriptor.

eyalm