如何在 C++ 中执行此操作:
假设程序 A
是一个带有一些输入(例如文件路径和数字)的命令行工具,根据它的输入,它可能会在运行时获取一些其他参数。 (if(condithin) cin<) 我想从另一个程序 B
调用 A
并希望查看完整的输出A
在运行期间。必须输入 A
的输入(如有必要)。 B
是一个用 Qt 编写的 GUI 工具,A
必须显示在纯文本区域中,并且它的输入必须显示在同一位置(如控制台客户端)。
我只是不知道从哪里开始。阅读有关 IPC 的内容并没有帮助。我知道这是可能的,因为我在 Eric IDE 中看到了 Dolphin 的控制台窗口和 python 解释器......
Howto do this in c++:
Suppose that program A
is a command line tool with some inputs (for example file paths and a number), according to it's inputs, it may get some other parameters during runtime. (if(condithin) cin<<something
) I'd like to call A
from another program B
and want to see complete output of A
during it's running. A
's inputs must be entered (if necessary). B
is a gui tool written with Qt and A
must be shown in a plain text area and it's inputs must be shown in same place (like a console client).
I just don't know where to start. Reading something about IPC didn't help. I know it's possible because I see Dolphin's console window and python interpreter in Eric IDE...
发布评论
评论(2)
使用 QProcess::execute 方法开始运行 A。你可以形成从 B 传递到 A 的参数列表。使用 QProcess::readAllStandardOutput () 读取进程的输出并显示在 B 中。
use QProcess::execute method to start running A. you can form the argument list from B to pass to A. Use QProcess::readAllStandardOutput () to read the output of the process and display in B.
由于您使用 Qt,因此使用 QProcess 可能是最好的方法。
Since you use Qt, using QProcess is probably the best way to do it.