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. |
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.
|
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.
|
By the way, are you talking shell/bash programming here? Or C?
|
heh...I was assuming C.....I get's it's true what they say about assuming....
Aaron |
c - u assumed right
|
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() |
All times are GMT -5. The time now is 01:52 PM. |