Home

DrPetri

This library is a simple support for using bidirectional namedpipes with python.
This library works on windows only.

How to install

Install on Windows see Download section, just launch the executable file.

How to compile

To compile with visual studio, execute:

setup.py install

To compile using mingw, execute:

setup.py install -cmingw32

Use exemple

Here is an exemple of python interracting with CPP. Launch the python script first, then compile and launch the test program.

python code

import pipe
pipe.create('\\.\PIPE\mypipe')
print pipe.read()
pipe.write('hello from python')
pipe.close()

cpp code



#include <iostream>

#include <fstream>

#include <windows.h>

#define pipename "\\.\PIPE\mypipe"

using namespace::std;

int main(void){

    char buffer[512];

    DWORD read_ret;

    HANDLE hPipe=CreateFile(pipename, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

    strcpy(buffer, "hello from cpp");

    WriteFile(hPipe,buffer, sizeof(buffer), &read_ret, NULL);

    ReadFile(hPipe, buffer, sizeof(buffer), &read_ret, NULL);

    buffer[read_ret]='\0';

    cout << buffer << endl;

    CloseHandle(hPipe);

}