I want to feed input to a C program with a perl script like this
./cprogram $(perl -e 'print "\xab\xcd\xef";').
However, the string must be read from a file. So I get something like this:
./cprogram $(perl -e 'open FILE, "<myfile.txt"; $file_contents = do { local $/; <FILE> }; print $file_contents'. However, now perl interprets the string as the string "\xab\xcd\xef", and I want it to interpret it as the byte sequence as in the first example.
How can this be achieved? It has to be ran on a server without File::Slurp.
In the first case, you pass the three bytes
AB CD EF(produced by the string literal"\xAB\xCD\xEF") toprint.In the second case, you must be passing something other than those three bytes to
print. I suspect you are passing the twelve character string\xAB\xCD\xEFtoprint.So your question becomes: How does one convert the twelve-character string
\xAB\xCD\xEFinto the three bytesAB CD EF. Well, you’d require some kind of parser such asAnd here it is at work: