开发者

Launching a console app from gui front-end

Could you please tell me the best way to do it? I can use popen, but it is nesessary to create a large buffer for arguments every time I need to launch my application. I can use fork + execv, but then the pr开发者_运维知识库ogram writes to stdout and I cant read the output ( to display it in the text field ) Is there any other solution?


Could you please tell me the best way to do it? I can use popen, but it is nesessary to create a large buffer for arguments every time I need to launch my application.

popen() is one good standard way if you only need one way communication with the child application, like writing to its stdin or reading from stdout, but not both.

When using C one needs to be comfortable with strings. It helps a lot to use a string library for C to ease string operations, such as string concatenation in your case, because the standard C library provides only basic low-level functions for that.

I can use fork + execv, but then the program writes to stdout and I cant read the output ( to display it in the text field )

popen() gives you a FILE* pointer to the child program's stdout from which you can read its output using the standard C I/O function fread() or fscanf(). Again, the standard C library has this functionality and it pays to familiarize yourself with it.

Is there any other solution?

You can make the child program write to a file and then read that file, but in any case you need to be able to construct the command line string and read the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜