Reputation: 30906
I want to run a command in terminal and capture output so I'm using
my $output = `command`;
The problem is the command has syntax highlighting so then I do print later on I loose the syntax highlighting and instead get things such as
print $output;
Result
←[31merror←[39m ←[
How can I either get the command without syntax highlighting or somehow get the syntax highlighting to display on print.
Upvotes: 2
Views: 179
Reputation: 316
Try this to remove the ANSI color escapes from the shell output:
my $output = `command`;
my $output =~ s/\e\[[\d;]*m//g;
print "$output","\n";
If you want to remove all ANSI escape-sequences, then replace the regexp with:
s/\e\[?.*?[\@-~]//g
Upvotes: 1