Thread: C++ and Shell

  1. #16
    Registered User tekhawk's Avatar
    Join Date
    Aug 2006
    Location
    USA Ca
    Posts
    25
    i was looking around the forums and found a topic like this one in linux programming but there are only 2 messages

    so my question would be do you guys know anything about

    popen()

  2. #17
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613

  3. #18
    Registered User tekhawk's Avatar
    Join Date
    Aug 2006
    Location
    USA Ca
    Posts
    25
    what is a pipe

    what im looking at this for is as a simple fast way to get data back from system functions

    such as the return from starting a program

    or the output of the ls command

    is there anyone that can show a simple use of popen and the ls command
    or the echo command

  4. #19
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> what is a pipe

    Who knows? Perhaps it's like the tubes and dump trucks.



    System, apparently, returns whatever the command it executes is meant to return. ie - ls may return 1 if it is successful, 0 if not, 42 if it finds the question, but you have to know what it should return ... Perhaps it returns the amount of files/folders in the directory. You have to know to use what it returns.

  5. #20
    Registered User tekhawk's Avatar
    Join Date
    Aug 2006
    Location
    USA Ca
    Posts
    25
    i need to caputer the output that ls or echo would out put into a string

    echo 'hello world'

    would out put

    hello world

    in term i need to know how to stop that and have it output to a string in c++

  6. #21
    Registered User tekhawk's Avatar
    Join Date
    Aug 2006
    Location
    USA Ca
    Posts
    25
    How in the world do you add sigs on this forum i havnt found that out yet

  7. #22
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> i need to caputer the output that ls or echo would out put into a string

    eh ... right ... ? Could you explain again?




    EDIT - Sigs, I can help you with. Go to top of screen, click on 'User CP', then there should be something about signatures or something.

  8. #23
    Registered User tekhawk's Avatar
    Join Date
    Aug 2006
    Location
    USA Ca
    Posts
    25
    if i type into commandline
    Code:
    echo "hello world"
    it outputs
    Code:
    hello world
    what i want to do is capture that in a string
    this is just a simple example im going to use this for something that makes sence but this question will give me the info i need

  9. #24
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    But why? Can't you just

    std::cout<< "Hello world!";

    ?

  10. #25
    Registered User tekhawk's Avatar
    Join Date
    Aug 2006
    Location
    USA Ca
    Posts
    25
    like i said this is just a example

    i might want to do something like

    capture the info from a ping command

    and use that data in the program

  11. #26
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Twomers missed the point
    I'm pretty sure that the man page will help you understand how popen works. Even if I give you a sample which echos hello world by piping it, it's not going to do you any good because it has nothing to do with what you are really trying to accomplish. The man page gives better examples anyway.

  12. #27
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> Twomers missed the point

    Don't be sad citizen! It's not your fault. But I did miss it. I thought he meant something completely different. Good thing someone has their heads screwed on!

    (citizen - Small t for twomers)

  13. #28
    Registered User tekhawk's Avatar
    Join Date
    Aug 2006
    Location
    USA Ca
    Posts
    25
    lol ok ill see what the man pages give me
    Web Devlopment is fun http://tekhawk.com

    Dur Ritter Von Gott

    OpenSource & Linux for Life!!!

  14. #29
    Registered User tekhawk's Avatar
    Join Date
    Aug 2006
    Location
    USA Ca
    Posts
    25
    err

    umm the man page for that command make my head hurt

    anyway i could get that sample on echo command
    Web Devlopment is fun http://tekhawk.com

    Dur Ritter Von Gott

    OpenSource & Linux for Life!!!

  15. #30
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    C++ is not a shell scripting language. if all you want is to capture the output of commands like ping and so on, I suggest you learn a bit more about the linux shell first. This is easily accomplished with a pipe and is more the "linux" way of doing things.

    if you give a more concrete example of what you're trying to achieve, we can show the more correct C++ way.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed