由C中的管道控制的ftp客户端
我正在尝试从 C 程序(OS X)控制 ftp 客户端。我做了 fork 和 execve - 进程启动正常。问题在于管道 - 我可以将命令发送到 ftp 客户端进程并从中获取反馈就好(如果我发送“help\n”,我会得到帮助输出),但我在管道中从未得到的是“ftp>”提示。有什么想法吗?
伊万
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 stdin/stdout 是终端或其他东西,您的 ftp 客户端的行为可能会有所不同(很多程序都会这样做,首先 C 库会以不同的方式进行缓冲...)如果您想控制它,请搜索有关伪的信息-终端,这有点太技术性了,无法在这里解释。 (首先查看像
expect
这样的程序,您可能不必编写自己的程序)。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).程序可以检查 stdin 来确定它是终端还是管道。在您的情况下,FTP 程序可能会这样做(例如,了解它是否可以使用转义序列来呈现进度条或提供命令行编辑)。
如果您确实需要提示,则必须查看 PTY(伪终端),模拟控制台。
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.
疯狂猜测:不是“ftp>”提示写入 STDERR ?
wild guess: isn't the "ftp>" prompt written to STDERR ?