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()
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()
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
>> 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.
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++
How in the world do you add sigs on this forum i havnt found that out yet
>> 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.
if i type into commandlineit outputsCode:echo "hello world"what i want to do is capture that in a stringCode:hello world
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
But why? Can't you just
std::cout<< "Hello world!";
?
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
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.
>> 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)
lol ok ill see what the man pages give me
err
umm the man page for that command make my head hurt
anyway i could get that sample on echo command
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?