Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to safely encode / pass arguments to a shell command where the argument might be binary? I'm executing a command from within a PHP script that allows for user data. For security, however, I obviously want this data escaped. Moreover, sometimes the data may be binary in nature so simple quoting of the shell command doesn't seem like it would suffice. What's the best approach for making sure a shell command's argument is properly escaped even if the argument data is binary?

share|improve this question
I am very curious as what shell command you intend to call with binary data as an argument, instead of piped into stdin. – DerfK Jan 4 '14 at 0:48
up vote 1 down vote accepted

You can encode it as base64 in PHP using base64_encode(), pass it to the shell, then decode it in the shell using base64 --decode.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.