Newbie Q: "Enter/Return" on popen

M

Ming

Hi there,

I was wondering if there was a way for popen to "hit the return key"
and continue along the same pipe. For instance in the code below, how
do I get popen to do "cd.." and then "dir/w"? I'm actually trying to
write code to run armsd - basically what happens is when you type
armsd at the c prompt, an "armsd prompt" appears, and then you type
"go" at that prompt to run armsd.
The problem here is that "go" doesn't work from the C prompt.

#include <stdio.h>
#include <string.h>
int main( )
{
FILE* handle; // handle to one end of pipe
char message[256]; // buffer for text passed through pipe
int status; // function return value

// Question: How do I get a "cd.." (or whatever) before "dir/w"?
// open a pipe to receive text from a process running "DIR"
handle = _popen("dir/w", "rt");

// read and display input received from the child process
while (fgets(message, sizeof(message), handle))
{
fprintf(stdout, message);
}

status = _pclose(handle);

return(0);
}

Any help I can get on this will be very much appreciated.

Thanks in advance,
Ming
 
A

Attila Feher

Ming said:
Hi there,

I was wondering if there was a way for popen to "hit the return key"
and continue along the same pipe. For instance in the code below, how
[SNIP]

Please ask popen related questions in a POSIX newsgroup. If I recall it is
a POSIX function. In C++ there is no popen and there is no idea of an enter
key (only streams). I am even afraid that it may not be possible to give
you a "portable" answer to your question.

Attila
 
D

Default User

Attila said:
Hi there,

I was wondering if there was a way for popen to "hit the return key"
and continue along the same pipe. For instance in the code below, how
[SNIP]

Please ask popen related questions in a POSIX newsgroup. If I recall it is
a POSIX function. In C++ there is no popen and there is no idea of an enter
key (only streams). I am even afraid that it may not be possible to give
you a "portable" answer to your question.


Yes, it is POSIX.

<OT>
The popen() function opens a stream to an application that runs only one
way, so there is no way to get it to do what the OP wants. There are
techniques for doing that, but it's a bit more involved. The fine folks
on comp.unix.programmer will be delighted to help, I'm sure. CHECK THEIR
FAQ LIST FIRST!
</OT>




Brian Rodenborn
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top