J
John Wilkinson
Hi,
I have a simple C++ program example, I would dearly love to swap to perl.
It uses pipes, which I do not understand, and I was wondering if anyone
could convert this bit of code for me:
#include <stdio>
#include <string>
#include <sys/types>
#include <unistd>
int main (int argc, char* argv{}){
int n;
char line[1024];
while((n = read(STDIN_FILENO, line, 1024)) > 0) {
line[n]= '\0';
if (strcmp(line,"firstcommand" == 0) {
strcpy(line, "answer,= 1234 -2345 155 test");
}
else {
strcpy(line, "unknown command");
}
n = strlen(line);
if (write(STDOUT_FILENO, line, n) != n) {
fprintf(stderr,"Server can't write to stdout\n");
}
}
}
This is supposed to be a simple example server, started by another process,
and using pipes to communicate to this server.
Many regards,
John
I have a simple C++ program example, I would dearly love to swap to perl.
It uses pipes, which I do not understand, and I was wondering if anyone
could convert this bit of code for me:
#include <stdio>
#include <string>
#include <sys/types>
#include <unistd>
int main (int argc, char* argv{}){
int n;
char line[1024];
while((n = read(STDIN_FILENO, line, 1024)) > 0) {
line[n]= '\0';
if (strcmp(line,"firstcommand" == 0) {
strcpy(line, "answer,= 1234 -2345 155 test");
}
else {
strcpy(line, "unknown command");
}
n = strlen(line);
if (write(STDOUT_FILENO, line, n) != n) {
fprintf(stderr,"Server can't write to stdout\n");
}
}
}
This is supposed to be a simple example server, started by another process,
and using pipes to communicate to this server.
Many regards,
John