Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:27:48+00:00 2026-06-15T22:27:48+00:00

I want to feed input to a C program with a perl script like

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:27:49+00:00Added an answer on June 15, 2026 at 10:27 pm

    In the first case, you pass the three bytes AB CD EF (produced by the string literal "\xAB\xCD\xEF") to print.

    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\xEF to print.

    So your question becomes: How does one convert the twelve-character string \xAB\xCD\xEF into the three bytes AB CD EF. Well, you’d require some kind of parser such as

    s/\\x([0-9a-fA-F][0-9a-fA-F])|\\([^x])|([^\\]+)/
       $1 ? chr(hex($1)) : $2 ? $2 : $3
    /eg
    

    And here it is at work:

    $ perl -e'print "\\xAB\\xCD\\xEF";' >file
    
    $ echo -n "$( perl -0777pe'
         s{\\x([0-9a-fA-F][0-9a-fA-F])|\\([^x])|([^\\]+)}{
            $1 ? chr(hex($1)) : $2 // $3
         }eg;
      ' file )" | od -t x1
    0000000 ab cd ef
    0000003
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want add new Feed item on entity persist and update. I write this
I have a program that calls a Filewatcher function, like this Main() { watch();
I have a method search that I want to feed an input stream and
I have this one liner: perl -pe 's|.*?((\d{1,3}\.){3})xxx.*|\1|' I feed this command with some
I want to display data feed from an external database in a sidebar in
I want to use Goolge AJAX Feed API in my C# console application to
I want to parse an existing RSS feed from another website with php and
We want to implement a News feed where a user can see messages broadcasted
I want to save an RSS feed to an xml document on my computer.
I want to read a specific line of a RSS feed to display the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.