Thanks for your suggestions. I will try them.
Sorrry, I didn't find out how you edit posts
colorama seems to do the same: Print an ANSI escape character sequence and therefore throws errors:
However this:
With termcolor it seems that you need to predefine the text's color (colored("some text")). I also want the output of my called command in green...
pygment seems not suitable for this, too. It uses HTML, HTML formatter and so on.
Aquaplant
Sorrry, I didn't find out how you edit posts
colorama seems to do the same: Print an ANSI escape character sequence and therefore throws errors:
import subprocess print("Some text in default color.") subprocess.run(["ls -l"], shell=True) print("Hopefully some text in default color, again.")Runs smoothly.
However this:
import subprocess from colorama import Fore print("Some text in default color.") subprocess.run([Fore.GREEN, "ls -l", Fore.RESET], shell=True) #or subprocess.run(["%sls -l%s" % (Fore.GREEN,Fore.RESET)], shell=True) OR subprocess.run(["%s; " % Fore.GREEN, "ls -l;" "%s" % Fore.RESET], shell=True) print("Hopefully some text in default color, again.")Throws an error:
Output:Some text in default color.
Hopefully some text in default color, again.
ls -l: 1: ls -l: : not found
This sometimes works for the first rows (still terminating with errors):subprocess.run(["%s; ls -l; %s" % (Fore.GREEN,Fore.RESET)], shell=True)
Output:/bin/sh: 1: : not found
/bin/sh: 1: : not found
Do I misuse the argument list or something? Could it be the encoding of the shell?With termcolor it seems that you need to predefine the text's color (colored("some text")). I also want the output of my called command in green...
pygment seems not suitable for this, too. It uses HTML, HTML formatter and so on.
Aquaplant