ruby - Write string with null characters to stdin of program -


i'm attempting write ruby wrapper native message client, can open external program interfaces website in chrome via command line. native message protocol message that's json encoded (in utf-8) that's preceded 32 bit integer of message length, in binary. native message client takes message through stdin , gives message encoded in same way via stdout.

that have tried doing is:

message = '{"message":"version"}' input = [message.length, message].pack('la*') output = `./mynaclprogram #{input}` puts output 

the problem when run this, following error: string contains null byte (argumenterror). presumably fact there \0 when message turned uint32.

how can pass input string native message client without ruby complaining null bytes within string? can use different kind of string, or pass in different way?

this not ruby-specific problem. arguments on nix system passed null-terminated strings (see exec(2) more details). means null characters 1 type of characters arguments command can't have. you'll need think of way of passing null-containing message in different way via arguments. (stdin simplest alternative).


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -