LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-07-2003, 12:44 PM   #1
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 45
store output of cmd in array?


hello.
im trying to save the output of a command, like "ls" into a char array.
the exec commands return ints, and i dont know how to have the output stored in some array rather than being printed on console.

thanks in advance.
 
Old 10-07-2003, 12:56 PM   #2
orgcandman
Member
 
Registered: May 2002
Location: dracut MA
Distribution: Ubuntu; PNE-LE; LFS (no book)
Posts: 594

Rep: Reputation: 102Reputation: 102
if you're trying to execute a separate program and then save that output, exec isn't the command for you unless you fork() first. exec overwrites your program's address space with the new program. you're looking to use something like system("./execute me > foo.txt"); and then read foo.txt for any results.
 
Old 10-07-2003, 01:28 PM   #3
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Original Poster
Rep: Reputation: 45
thank you very much - will do as you suggested. i was trying not to deal with files, and just have the output of the command moved into a variable ... but ill use files for now. thanks again.
 
Old 10-07-2003, 04:10 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
By the way, are you talking shell/bash programming here? Or C?
 
Old 10-07-2003, 04:28 PM   #5
orgcandman
Member
 
Registered: May 2002
Location: dracut MA
Distribution: Ubuntu; PNE-LE; LFS (no book)
Posts: 594

Rep: Reputation: 102Reputation: 102
heh...I was assuming C.....I get's it's true what they say about assuming....

Aaron
 
Old 10-07-2003, 04:30 PM   #6
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Original Poster
Rep: Reputation: 45
c - u assumed right
 
Old 10-09-2003, 09:46 PM   #7
jimveta
Member
 
Registered: Oct 2003
Location: los angeles
Posts: 32

Rep: Reputation: 15
if there are system calls or libc functions that do a subset of some
user command, it may be more convenient ( .. or maybe not ) to just
use those instead of outputting to a text file then parsing it

for example with ls, you can use readdir()
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
store output of iwconfig ppb Linux - Wireless Networking 1 04-13-2005 01:59 AM
How do i store the output of an rpm or source to file? dr_zayus69 Linux - Software 8 03-07-2005 10:03 AM
using > to store output student04 Linux - General 2 01-21-2005 08:51 PM
xcdroast - cdrecord.mmap: Input/output error. write_g1: scsi sendcmd: cmd timeout masgari Linux - Software 11 03-17-2004 11:55 PM
Awk and Shell CMD Output xanthium Programming 16 04-24-2002 07:13 AM


All times are GMT -5. The time now is 01:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration