Python Forum
subprocess.call change color of shell
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
subprocess.call change color of shell
#5
Thanks for your suggestions. I will try them.

Sorrry, I didn't find out how you edit posts Huh

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
Reply


Messages In This Thread
RE: subprocess.call change color of shell - by Aquaplant - Jan-19-2017, 09:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 1,159 Oct-25-2023, 09:09 AM
Last Post: codelab
  simplekml change shape&color issac_n 2 2,907 Aug-20-2022, 07:15 PM
Last Post: Joseph_Paintsil
  continue if 'subprocess.call' failes tester_V 11 5,373 Aug-26-2021, 12:16 AM
Last Post: tester_V
  printing out the contents aftre subprocess.call() Rakshan 3 2,834 Jul-30-2021, 08:27 AM
Last Post: DeaD_EyE
  subprocess call cannot find the file specified RRR 6 16,895 Oct-15-2020, 11:29 AM
Last Post: RRR
  Change the color automatically Dragonos 5 2,970 Jul-28-2020, 01:17 PM
Last Post: Dragonos
  Use of input function to change screen background color in Turtles Oldman45 3 5,022 Jul-10-2020, 09:54 AM
Last Post: Oldman45
  Why wont subprocess call work? steve_shambles 3 2,737 Apr-28-2020, 03:06 PM
Last Post: steve_shambles
  subprocess.call - Help ! sniper6 0 1,559 Nov-27-2019, 07:42 PM
Last Post: sniper6
  How to use subprocess send commands to windows shell hlhp 3 4,517 Nov-26-2019, 04:40 AM
Last Post: LeanbridgeTech

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020