Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with pipe : EPIPE read. #10415

Closed
ambrt opened this issue Dec 22, 2016 · 2 comments
Closed

Problem with pipe : EPIPE read. #10415

ambrt opened this issue Dec 22, 2016 · 2 comments
Labels
net Issues and PRs related to the net subsystem. question Issues that look for answers.

Comments

@ambrt
Copy link

ambrt commented Dec 22, 2016

I'm trying to make a pipe request to Dropbox application on window (not the Dropbox API)
But i'm getting

{ [Error: read EPIPE] code: 'EPIPE', errno: 'EPIPE', syscall: 'read' }

Could anyone look into this code an tell what might be wrong?

var net = require('net');
var ffi = require('ffi');
var ref = require('ref');
var BufferStream = require('node-bufferstream')

var PIPE_PATH = "\\\\.\\pipe\\DropboxPipe_1"
var UserName = "YourUserName"
var L = console.log;
var struct = require('python-struct');

var SessionId = ref.alloc("uint");

var encoding = require("encoding");

var kernel32 = new ffi.Library("kernel32",{
    GetLastError:['string',[]],
    GetCurrentProcessId: ['int',[]] ,
    GetCurrentThreadId: ['int',[]],
    ProcessIdToSessionId: ['bool',['int','uint *']],
    CallNamedPipeA:['bool',[]]

});



var RequestInfo = 0x3048302;
var ProcessId = kernel32.GetCurrentProcessId();
var ThreadId = kernel32.GetCurrentThreadId();
var RequestType =1;
var dropbox = ref.types.void;

if(!kernel32.ProcessIdToSessionId(ProcessId,SessionId )){
    console.log(kernel32.GetLastError());
}
else{
    //console.log(SessionId);
    SessionId.type = ref.types.int;
    SessionIdInt = SessionId.deref();
    console.log(SessionIdInt);
}

var mypath = "C:/Users/"+UserName+"/Dropbox/"
var L = console.log;



var client = net.createConnection({ path: '\\\\.\\pipe\\DropboxPipe_1'}, function () { 
    console.log('connected');
    var wtf = 0x3048302;
    var request = struct.pack("LLLL",wtf,ProcessId, ThreadId,RequestType)  + encoding.convert(mypath,"utf-16le")
    var str = new Array(540 + 1).join( String.fromCharCode(0) );
    request = request + str;
    var request = request.substr(0,540);
    client.write(request, ()=>{
        console.log("write callback"); //this part is written to console
        console.log(client.bytesWritten) // 550
        console.log(client.bytesRead)    //0
    });                                                                               

});


client.on("error", function(e) { console.log(e); });

client.on('data', function(data) {
    L('Client: on data:', data.toString());
    client.end('Thanks!');
});

client.on('end', function() {
    L('Client: on end');
})
@Fishrock123 Fishrock123 added the question Issues that look for answers. label Dec 22, 2016
@mscdex
Copy link
Contributor

mscdex commented Dec 22, 2016

This is probably best asked on the nodejs/help repo unless it can be verified that there is a bug in node.

@mscdex mscdex added the net Issues and PRs related to the net subsystem. label Dec 22, 2016
@Fishrock123
Copy link
Contributor

{ [Error: read EPIPE] code: 'EPIPE', errno: 'EPIPE', syscall: 'read' }

Could anyone look into this code an tell what might be wrong?

tl;dr: you're piping to a closed stream/file descriptor somewhere, perhaps something is closing it prematurely?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
net Issues and PRs related to the net subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

4 participants