Process: keep the colored output

Hi guys, I have a question. When I use Process.run, can it be possible to keep the command output color ?

For example, if I run this, the ouput is only black and white. But normally ls have a colored output:

Process.run("ls", shell: true, output: Process::Redirect::Inherit)

ls will by default not use color if its output is being piped. Look at “man ls” and look for the --color option for details.

You probably want ls --color=always

1 Like

that worked for me! glorious color! thanks!

def run_cmd(arg_str, cmd = “bash”, cmd_arg = “-c”)
args = of String
args << cmd_arg << arg_str
# printf(“run_cmd: arg_str is: %s\n\n”, arg_str)
Process.run(cmd, args, output: Process::Redirect::Inherit)
end

run_cmd(“ls --color=always”)