我必须执行一个 unix 交互式命令来启动另一个 ksh 交互式 shell,这样我就可以执行其他命令。
expect 或 tcl/tk 不可用,而且我似乎无法使用重定向(因为第一个交互式命令启动了其他我无法重定向(或不知道如何)输出的子项。
示例(非自动)
$ /bin/someComand username: xpto password: xpty someCommand is now executing other voodooshell: voodooshell$ /bin/anotherCommand This is the output you want.. bye .
第一部分很简单:
$ /bin/someCommand<<E xpto xpto E
尝试这样的方法是行不通的
$ /bin/someCommand<<E xpto xpto E<(otherPrettyCommands<<A who quit A )
所以我想......用popen 编写c 程序!? :-) 好吧,再次解决第一个问题很好,但是如何获取第一个问题的子进程并在它退出之前将命令重定向到它? :-(
你会如何解决这个问题?
最佳答案
如果您只想捕获输出(而不是注入(inject)输入),也许您可以运行 Linux 的等效程序
strace -ff -p pid
然后尝试解析 strace 的输出。
对于 HP-UX,我认为 strace 的等效项是 truss 或 tusc。 tusc 可以在以下位置下载: http://hpux.connect.org.uk/hppd/hpux/Sysadmin/tusc-8.1/
(但我从未在 HP-UX 中使用过 tusc 或 truss,所以我真的不知道这是否可行)。
关于c - 在 Hp-UX ksh 中执行交互式命令(意外)并获取子进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24654489/