Command pipes in C++

P

Peng Yuan Fan

Hi, sorry if you found I have multi posted in different groups. It didn't
appear in that group.

I am trying to write an automated testing program with CxxTest, which in
turn needs to talk to gdb through the command line.

The program should give some command to gdb, the debugger program. And then
get the results out of it. Just like when we debug with gdb, we type in
those commands, and see the results. But this has to be done in an automated
way.

It is very similar to the pipes in scripting language, but the test has to
be done with C++.

Please help. Thank you very much.

Peng
 
R

Rolf Magnus

Peng said:
Hi, sorry if you found I have multi posted in different groups. It
didn't appear in that group.

I am trying to write an automated testing program with CxxTest, which
in turn needs to talk to gdb through the command line.

The program should give some command to gdb, the debugger program. And
then get the results out of it. Just like when we debug with gdb, we
type in those commands, and see the results. But this has to be done
in an automated way.

It is very similar to the pipes in scripting language, but the test
has to be done with C++.

Please help. Thank you very much.

Peng

This is a platform sepcific question. Standard C++ has no way to open
such a pipe between two programs.

Under POSIX systems, you might want to have a look at the manual page of
the pipe() system call.
 
P

Peter van Merkerk

Peng said:
Hi, sorry if you found I have multi posted in different groups. It didn't
appear in that group.

I am trying to write an automated testing program with CxxTest, which in
turn needs to talk to gdb through the command line.

The program should give some command to gdb, the debugger program. And then
get the results out of it. Just like when we debug with gdb, we type in
those commands, and see the results. But this has to be done in an automated
way.

It is very similar to the pipes in scripting language, but the test has to
be done with C++.

Standard C++ has no support for pipes; you need platform specific
methods to accomplish what you want. Maybe your platform supports the
popen() function.
 
D

David Rubin

Peng Yuan Fan said:
Hi, sorry if you found I have multi posted in different groups. It didn't
appear in that group.

I am trying to write an automated testing program with CxxTest, which in
turn needs to talk to gdb through the command line.

Use Expect.
It is very similar to the pipes in scripting language, but the test has to
be done with C++.

Not a compelling reason.

/david
 
E

Evan Carew

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi, sorry if you found I have multi posted in different groups. It didn't
appear in that group.

I am trying to write an automated testing program with CxxTest, which in
turn needs to talk to gdb through the command line.
[snip]
Since you are already using the gcc tool chain, arguments to the effect
that pipes are platform specific are not necessarily valid as even on MS
products, as long as you install the cigwin environment, you have pipes.
That being said, your only issue is to deal with the pipes man pages. To
start work with pipes, try looking up the following man pages: pipe
(gives you 2 file descriptors), dup2 (which allows you to redirect input
& output), and fork.

Generally, you create your in/out pair with something like pipe prior to
forking, then in the child, redirect your IO to the appropriate fd. Ok,
so all that sounds great, but as one of the previous respondents said,
if you don't need to use this in an existing C++ program, expect isn't a
bad choice of an app to use which already has this all tied up.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFA5Du3oo/Prlj9GScRAmGfAJ4pSdrwvtdoupLNpTpfqOzeMMlsIgCfQFJE
tI+9jUnYfKcx0yjN7mW4oyc=
=6z0v
-----END PGP SIGNATURE-----
 
P

Peter Vos

Hi, sorry if you found I have multi posted in different groups. It didn't
appear in that group.

I am trying to write an automated testing program with CxxTest, which in
turn needs to talk to gdb through the command line.

The program should give some command to gdb, the debugger program. And then
get the results out of it. Just like when we debug with gdb, we type in
those commands, and see the results. But this has to be done in an automated
way.

It is very similar to the pipes in scripting language, but the test has to
be done with C++.

Take a look at http://libexecstream.sourceforge.net/
From the project's description:
"Libexecstream is a C++ library that allows you to run a
child process and have its input, output and error avaliable
as standard C++ streams."

HTH,
Peter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top