从system()读取输出。 [英] Read output from system( ).

查看:76
本文介绍了从system()读取输出。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要读取C程序中system()函数的输出。

但该函数只返回退出状态。

如何读取system()发送到stdout的内容?

(有没有比分叉子进程更简单的方法然后

抓住它输出?)

(如果需要:在linux上工作)


谢谢

Hi,
I need to read the output from a system( ) function within a C program.
The function however only returns the exit status.
How can I read what system( ) sends to stdout ?
(is there a simpler way than having to fork a child process and then
catching its output ?)
(if needed: working on linux)

Thanks

推荐答案

SR写道:

我需要读取C程序中system()函数的输出。
该函数只返回退出状态。


对,它做的是什么。

如何读取系统()发送到stdout的内容?
(有比这更简单的方法吗?必须分叉一个子进程,然后才能获取其输出?)


不在标准C.

(如果需要:在linux上工作)
Hi,
I need to read the output from a system( ) function within a C program.
The function however only returns the exit status.
Right, that what it does.
How can I read what system( ) sends to stdout ?
(is there a simpler way than having to fork a child process and then
catching its output ?)
Not in standard C.
(if needed: working on linux)




如果相关,你的问题不在话题。


< OT>

所以你不要'gorge out''(只有一次''报价):


男人popen

< / OT>


将来,请在此处仅发布有关标准C的问题,对于

一般的Unix问题使用:


新闻:comp.unix.programmer


和Linux特定问题使用:


news:comp.os.linux.development.apps


HTH,

- g


-

Artie Gold - 德克萨斯州奥斯汀

哦,对于常规旧垃圾邮件的美好时光。



If relevant, your question is off topic.

<OT>
Just so you don''t `gorge out'' (a `one time only'' offer):

man popen
</OT>

In the future, please post only questions about standard C here, For
general Unix questions use:

news:comp.unix.programmer

and for Linux specific questions use:

news:comp.os.linux.development.apps

HTH,
--ag

--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.


A rtie Gold< ar ******* @ austin.rr.com>写道:
Artie Gold <ar*******@austin.rr.com> wrote:
SR写道:

我需要读取C程序中system()函数的输出。
该函数但是只返回退出状态。
对,它的作用。
Hi,
I need to read the output from a system( ) function within a C program.
The function however only returns the exit status.
Right, that what it does.
如何读取system()发送到stdout的内容?
(是否有比分叉子进程然后获取其输出更简单的方法?)
How can I read what system( ) sends to stdout ?
(is there a simpler way than having to fork a child process and then
catching its output ?)



不在标准C中。



Not in standard C.

(如果需要:在linux上工作)
(if needed: working on linux)



如果相关,你的问题不在话题。

< OT>
只是你不要'' t`gorge out''(一次'只提供一次''报价):

man popen
< / OT>

将来,请发帖这里只有关于标准C的问题,对于
一般的Unix问题使用:



If relevant, your question is off topic.

<OT>
Just so you don''t `gorge out'' (a `one time only'' offer):

man popen
</OT>

In the future, please post only questions about standard C here, For
general Unix questions use:




如果OP不知道答案,他怎么会知道有没有

标准C答案但是一个Unix的答案确实存在吗?


无论如何,有一个标准的C答案,它只是没有/ b $ b恰好和unix一样好popen()方法。给予system()函数的命令

可以将stdout重定向到一个文件。

程序然后只需读取文件。

news: comp.unix.programmer

和Linux特定问题的使用:

新闻:comp.os.linux.development.apps



If the OP didn''t know the answer, how would he know there was no
Standard C answer but that a Unix answer does exist?

Regardless, there is a Standard C answer, which just doesn''t
happen to be as nice as the unix popen() method. The command
given to the system() function can redirect stdout to a file.
The program then simply reads the file.
news:comp.unix.programmer

and for Linux specific questions use:

news:comp.os.linux.development.apps



顺便提一下,对于OP来说,这两个组都可能是更好的地方,可以用来编程编程。任何形式的问题。

Clc是C律师,而不是C编程。


-

Floyd L. Davidson< ; http://web.newsguy.com/floyd_davidson>

Ukpeagvik(巴罗,阿拉斯加州) fl *** @ barrow .com


SR写道:

我需要从一个system()函数中读取输出C
程序。但该功能仅返回退出状态。我怎样才能读取system()发送到stdout的内容? (有没有比分叉子进程然后捕获它的
输出更简单的方法?)(如果需要:在linux上工作)

I need to read the output from a system( ) function within a C
program. The function however only returns the exit status. How
can I read what system( ) sends to stdout ? (is there a simpler
way than having to fork a child process and then catching its
output ?) (if needed: working on linux)




叉?儿童?处理? Linux呢?这些都没有在C

标准中定义,因此你在这里是偏离主题的。什么系统()实际上

确实也取决于系统。所以你需要一个小组来处理你的系统,这显然是linux。使用它和unix到

搜索一个合适的团体。


-

查克F(cb ******** @ yahoo.com)(cb********@worldnet.att.net)

可用于咨询/临时嵌入式和系统。

< http: //cbfalconer.home.att.net>使用worldnet地址!



fork? child? process? linux? None of these are defined in the C
standard, and thus you are off-topic here. What system() actually
does is also system dependant. So you need a group dealing with
your system, which apparently is linux. Use that and "unix" to
search for a suitable group.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


这篇关于从system()读取输出。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆