G
G
Gibbon Cho2015-04-24 14:21:44
Perl
Gibbon Cho, 2015-04-24 14:21:44

How to write in Named Pipe in Perl?

There is a program written in c ++, it is a pipe server, the following code is executed in it:

HANDLE hPipe;
char buffer[1024];
DWORD dwRead;
String out = "";
hPipe = CreateNamedPipe(TEXT("\\\\.\\pipe\\mypipe"), PIPE_ACCESS_DUPLEX | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,  
              PIPE_WAIT,
              1,
              1024 * 16,
              1024 * 16,
              NMPWAIT_USE_DEFAULT_WAIT,
              NULL);
  while (hPipe != INVALID_HANDLE_VALUE)
  {
    if (ConnectNamedPipe(hPipe, NULL) != FALSE)   // wait for someone to connect to the pipe
    {
      out = "";
      while (ReadFile(hPipe, buffer, sizeof(buffer) - 1, &dwRead, NULL) != FALSE)
      {
        buffer[dwRead] = '\0';
        out += buffer;
      }
    }
    WriteLog(0,"PIPE",out); //Этот код выводит на экран значение переменной out
    DisconnectNamedPipe(hPipe);
  }

It is necessary for me that at performance of perl of a script the result was deduced in pipe. Here is my perl script:
sysopen(FIFO, "\\\\.\\pipe\\mypipe", O_WRONLY) or die "Couldn't open for writing: $!\n";
print FIFO "Hello world" or die "error print";
close FIFO;

The inscription "error print" is displayed
What am I doing wrong?
Server side commits connection but no data read

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2015-04-24
@gibboncho

#!/usr/bin/perl -w
while (1) {
    open(FIFO, "> \\\\.\\pipe\\mypipe")
        or die "writing: $!\n";
    print FIFO "The current time is ", scalar(localtime), "\n";
    close FIFO;
    sleep 1;
}

or
IO::Pipe

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question