Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > need help getting the results of the system function into a variable

Reply
Thread Tools

need help getting the results of the system function into a variable

 
 
SF
Guest
Posts: n/a
 
      02-27-2006
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.

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      02-27-2006
In article <(E-Mail Removed) .com>,
SF <(E-Mail Removed)> wrote:
>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?


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
 
Reply With Quote
 
 
 
 
SF
Guest
Posts: n/a
 
      02-27-2006
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.

 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      02-27-2006
In article <(E-Mail Removed) .com>,
SF <(E-Mail Removed)> wrote:
>Are you aware of a better function then system() to run a shell
>command? one that could return the output rather than an int.


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
 
Reply With Quote
 
Fred Kleinschmidt
Guest
Posts: n/a
 
      02-27-2006

"SF" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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.
>

If you have a POSIX-compliant system, use popen()
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project


 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      02-27-2006
SF wrote:

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


Anything else would be platform specific. You need to find a newsgroup
dedicated to your implementation or (perhaps) OS. Also, see the
information in my .sig below.


Brian
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
 
Reply With Quote
 
Ron Lima
Guest
Posts: n/a
 
      02-28-2006
> Are you aware of a better function then system() to run a shell
> command? one that could return the output rather than an int.


Have you tried CreateProcess system call to do so? I know that this
system call returns several information about the process that you
start with it. This is something specific for Windows platform and is
not STDC at all.

Check this link:
http://msdn.microsoft.com/library/de..._processes.asp

This has several information about creating processes on windows
platforms.

Hope that it helps.

Ron

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-28-2006
"Ron Lima" <(E-Mail Removed)> writes:
>> Are you aware of a better function then system() to run a shell
>> command? one that could return the output rather than an int.

>
> Have you tried CreateProcess system call to do so? I know that this
> system call returns several information about the process that you
> start with it. This is something specific for Windows platform and is
> not STDC at all.

[snip]

And if this information had been posted to a Windows-specific
newsgroup, the experts there could post any necessary corrections.
As it is, most of us have no idea whether the suggested solution will
actually work, or whether something else might be better.

If you want to discuss Windows-specific interfaces, please don't do it
here.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
jitendrapra@gmail.com
Guest
Posts: n/a
 
      02-28-2006
Its execpls( ) ... this works well on unix operating systems...

Jitendra

 
Reply With Quote
 
jitendrapra@gmail.com
Guest
Posts: n/a
 
      02-28-2006
sorry .... its execlp ( ) ...

thanks
jitendra

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable argument function as a parameter of a variable argument function AikidoGuy C Programming 11 11-21-2011 10:43 PM
Need help on getting the results from a URL SteveB Javascript 1 05-30-2006 10:13 AM
Read a recordset into a variable so I can disconnect from DB and use results? Noozer ASP General 1 02-06-2006 10:19 PM
getting results into one variable s99999999s2003@yahoo.com Python 4 11-10-2005 04:41 PM
win32- system call - getting results back into python gregpinero@gmail.com Python 2 05-07-2005 07:20 PM



Advertisments