tags:

views:

49

answers:

3

Hi!

I am trying to control ftp client from C program (OS X). I did fork and execve - process is started ok. The problem is with pipes - I can send command to ftp client process and get feedback from it just fine (If i send "help\n" i get back help output) but what I never get in pipe is "ftp> " prompt. Any ideas?

Ivan

A: 

wild guess: isn't the "ftp>" prompt written to STDERR ?

Adrien Plisson
+3  A: 

Your ftp client is probably behaving differently if stdin/stdout is a terminal or something else (lots of program do, for a start the C library does buffering in a different way...) If you want to control that, search information about pseudo-terminals, that's a little too technical to be explained here. (And looks first at programs like expect, it's possible you won't have to write yours).

AProgrammer
+1 for `expect`, it's designed for exactly this purpose.
Greg Hewgill
Ah, the memories of programming (with `expect`) the login dialogue to an old-fashioned (modem) ISP...
Pascal Cuoq
A: 

A program can examine stdin to find out whether it's a terminal or a pipe. In your case, the FTP program probably does that (for example to know whether it can use escape sequences to render progress bars or offer command line editing).

If you really need the prompt, you have to look into PTYs (pseudo terminals) which emulate a console.

Aaron Digulla