Thread: redirect to a variable from console ???

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    22

    redirect to a variable from console ???

    Hi friends,
    i have a doubt... can i redirect the output printed on the console to a variable in C program ?? (Eg: say i am using linux OS coding in C and inside the C code i have used system("date") which prints the date to the console !!! and now if i want the next statement in the C code to have this date's output in a charecter array... is this possible ????)sorry if i am talking something nonsense.. hahah...

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Use popen() to treat the input (or output) of other processes as FILE* handles (fgets, fprintf etc compatible)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    22
    thanks a lot for reply salem.....
    but really i didnt get what u are saying.... sorry...
    can u plese be more detail...

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    see if this page helps: http://tldp.org/LDP/lpg/node12.html

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Normally, when people say use the foo() function, your first reaction should be go read about it in the manual page, say

    man popen

    rather than saying "huh" every time someone uses a new function you've never heard of. We're not here to regurgitate every single manual page in small morcels for every single noob that wanders by.

    I showed you the door, you walk through it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    22
    thanks a lot for that link nadroj... that really helped me.....
    Quote Originally Posted by Salem
    man popen

    rather than saying "huh" every time someone uses a new function you've never heard of. We're not here to regurgitate every single manual page in small morcels for every single noob that wanders by.

    I showed you the door, you walk through it.
    i really agree with what u are saying...and i have not even asked to give the ready code for something...the first thing what i did was man popen.. really... but since i am a beginner in C and linux... had some problem in understanding and how to extract the info using the return value of the file pointer it returns....so i asked u to explain it a bit....
    Last edited by compile; 04-18-2007 at 03:07 AM.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You don't know how to read from a file? Don't you have a C book? Don't you know how to read a FAQ? Don't you know how to search the internet? It returns a file pointer. Use functions that read from file pointers. Pretty simple stuff.


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    I should have figured that would have been the response from the profusion of punctuation, and the "skiddie" speak.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    22
    Thanks all for suggestions.. i got the answer.... and from the next time i will be specific in asking quesitons....that should be better....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  2. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM
  3. variable being reset
    By FoodDude in forum C++ Programming
    Replies: 1
    Last Post: 09-15-2005, 12:30 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Linux console window questions
    By GaPe in forum Linux Programming
    Replies: 1
    Last Post: 12-28-2002, 12:18 PM