LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 11:44 AM   #1
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 46
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, 11:56 AM   #2
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
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, 12:28 PM   #3
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Original Poster
Rep: Reputation: 46
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, 03:10 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
By the way, are you talking shell/bash programming here? Or C?
 
Old 10-07-2003, 03:28 PM   #5
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

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

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

Original Poster
Rep: Reputation: 46
c - u assumed right
 
Old 10-09-2003, 08: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



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 12:59 AM
How do i store the output of an rpm or source to file? dr_zayus69 Linux - Software 8 03-07-2005 09:03 AM
using > to store output student04 Linux - General 2 01-21-2005 07:51 PM
xcdroast - cdrecord.mmap: Input/output error. write_g1: scsi sendcmd: cmd timeout masgari Linux - Software 11 03-17-2004 10:55 PM
Awk and Shell CMD Output xanthium Programming 16 04-24-2002 06:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:03 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
Open Source Consulting | Domain Registration