0

I am trying to display the output of a shell command using PHP's passthru function. I am getting an extra [0;32m where the actual shell output has a green line and am also getting an extra [m at the beginning of few other lines.

What do I need to do to get a PHP output without these additional characters?

My PHP command is:

passthru('/var/www/cCompiledScript');
1
  • Where did you get cCompiledScript? It may have a flag to turn off color output. Commented Sep 17, 2015 at 12:44

1 Answer 1

3

I don't know what cCompiledScript is, but clearly it is outputing ANSI escape sequences to generate color on the terminal. It may have a command line flag or environment variable that you can set to disable color output. If you wrote cCompiledScript you could add a flag to disable color. Otherwise you will have to strip out the color codes:

passthru('/var/www/cCompiledScript | sed "s/\x1B\[\([0-9]\{1,2\}\(;[0-9]\{1,2\}\)\?\)\?[mGK]//g"');

The sed command above is from this answer on the Unix & Linux Stack Exchange.

Sign up to request clarification or add additional context in comments.

2 Comments

cCompiledScript is a wrapper.c script.
I'm sorry, I don't know what that is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.