需要帮助将系统函数的结果转换为变量 [英] need help getting the results of the system function into a variable

查看:41
本文介绍了需要帮助将系统函数的结果转换为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,


在Windows C学习项目中,我正在使用系统

函数来运行命令,我想吮吸结果变成了可用的。

系统函数似乎只返回一个int。我想知道

这怎么可能呢?我现在只能看到一种方式而且我知道必须有更好的方法才能获得
。现在,我很想将
命令的输出传递给临时文件,然后从文件中获取数据

。这对我来说真的很脏,你能建议一个更好的

方式吗?


非常感谢提前。

Hello All,

In a windows C learning project I am wokring on I use the system
function to run a command, I want to suck the results into a vairable.
The system function seems to only return an int. I would like to know
how could this is done? I can see only one way currently and I know
that there must be a better method. Right now I would be tempted to
pipe the output of the command to a temp file and then get the data
from the file. That seems really dirty to me, can you suggest a better
way?

Much thanks in advance.

推荐答案

在文章< 11 ********************** @ z34g2000cwc.googlegroups .com>,

SF< so *********** @ gmail.com>写道:
In article <11**********************@z34g2000cwc.googlegroups .com>,
SF <so***********@gmail.com> wrote:
在一个Windows C学习项目中,我正在使用系统
函数来运行一个命令,我想将结果吸收到一个可修复的。
系统函数似乎只返回一个int。我想知道
怎么能这样做?


仅使用标准C无法做到这一点。

我目前只能看到一种方式而且我知道
必须有一种更好的方法。现在,我很想将命令的输出传递给临时文件,然后从文件中获取数据。这对我来说真的很脏,你能建议一个更好的方式吗?
In a windows C learning project I am wokring on I use the system
function to run a command, I want to suck the results into a vairable.
The system function seems to only return an int. I would like to know
how could this is done?
There is no way to do it using only standard C.
I can see only one way currently and I know
that there must be a better method. Right now I would be tempted to
pipe the output of the command to a temp file and then get the data
from the file. That seems really dirty to me, can you suggest a better
way?




管道是特定于操作系统的扩展,在
$ b之外$ b控制标准C.标准C甚至没有定义结果

使用system():它只是说它存在并且结果

正在运行 - 系统依赖。


可能你的意思是重定向而不是管道,但是将
重定向system()输出到文件中的能力再次依赖于操作系统

(虽然它可能在比支持更多的操作系统

管道。)


对于它的价值,处理这个的通常POSIX是使用

popen(),但是如果你想知道

Windows中有哪些设施,你应该检查Windows编程新闻组。


-

当时我很年轻,但我也很朦胧。

- 克里斯托弗牧师



pipes are operating system-specific extensions, outside the
control of standard C. Standard C does not even define the result
of using system(): it just says that it exists and that the result
is operating-system dependant.

Possibly you meant "redirect" instead of "pipe", but the ability to
redirect system() output into a file is again operating-system dependant
(though it''s probably available on more operating systems than support
pipes.)

For what it''s worth, the usual POSIX of handling this is to use
popen(), but if you want to know what facilities are available in
Windows, you should check a Windows programming newsgroup.

--
I was very young in those days, but I was also rather dim.
-- Christopher Priest


谢谢你的回复,


我使用的是重定向而不是管道。我想我没有在那里使用正确的

术语。


你是否知道一个更好的功能然后system()来运行一个shell

命令?一个可以返回输出而不是int。


感谢您的帮助。

Thanks for the reply,

I am using redirect rather than a pipe. I guess I did not use the right
term there.

Are you aware of a better function then system() to run a shell
command? one that could return the output rather than an int.

Thanks for your help.


在文章< ; 11 ********************** @ t39g2000cwt.googlegroups .com>,

SF< so ****** *****@gmail.com>写道:
In article <11**********************@t39g2000cwt.googlegroups .com>,
SF <so***********@gmail.com> wrote:
你是否知道一个更好的功能,然后system()来运行一个shell
命令?一个可以返回输出而不是int。
Are you aware of a better function then system() to run a shell
command? one that could return the output rather than an int.




正如我所说,system()就是标准C中的所有内容,以及任何内容
$ b应该在特定于您的

操作系统的新闻组中询问$ b else。当您在那里发布时,请务必指定您的Windows和Service Pack的

版本,因为答案可能是

,具体取决于您安装的内容。

-

有些想法错了,只有一个非常聪明的人才能相信他们。 - George Orwell



As I indicated, system() is all you get in standard C, and anything
else should be asked about in a newsgroup specific to your
operating system. When you post there, be sure to specify your
version of Windows and Service Pack(s), as the answer might be
dependant upon exactly what you have installed.
--
There are some ideas so wrong that only a very intelligent person
could believe in them. -- George Orwell


这篇关于需要帮助将系统函数的结果转换为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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