python - Get output colored text with Popen -


i'm using popen make plugin, plugin used external program shows colored text in output.

the output this:

avr-g++ -o .pioenvs\uno\frameworkarduino\hardwareserial.o -c -std=gnu++11 -fno-exceptions -fno-threadsafe-statics -g -os -wall -ffunction-sections -fdata-sections -mmcu=atmega328p -df_cpu=16000000l -darduino_arch_avr -darduino_avr_uno -darduino=10607 -i.pioenvs\uno\frameworkarduino -i.pioenvs\uno\frameworkarduinovariant .pioenvs\uno\frameworkarduino\hardwareserial.cpp     avr-g++ -o .pioenvs\uno\frameworkarduino\hardwareserial0.o -c -std=gnu++11 -fno-exceptions -fno-threadsafe-statics -g -os -wall -ffunction-sections -fdata-sections -mmcu=atmega328p -df_cpu=16000000l -darduino_arch_avr -darduino_avr_uno -darduino=10607 -i.pioenvs\uno\frameworkarduino -i.pioenvs\uno\frameworkarduinovariant .pioenvs\uno\frameworkarduino\hardwareserial0.cpp ============================================= path\file.cpp: in function 'void loop()': path\file.cpp:23:2 error: expected ';' before '}' token } ^ ============================================= 

all inside "=" in red , yellow.

when run command in command console, can see full output, when use popen can uncolored text

this how i'm using popen

process = subprocess.popen(command, stdin=subprocess.pipe, stdout=subprocess.pipe, cwd=self.cwd, universal_newlines=true, shell=true) output = process.communicate()  stdout = output[0] stderr = output[1]  print(stdout) print(stderr) 

i text if it's not colored, important full log.

any suggestion appreciated

you not able message because part of command output not regular output, considered error (or log or debug messages)

now can either add stderr=subprocess.pipe popen's parameters, put errors in stderr variable:

process = subprocess.popen(command, stdin=subprocess.pipe, stdout=subprocess.pipe, stderr=subprocess.pipe, cwd=self.cwd, universal_newlines=true, shell=true) output = process.communicate()  stdout = output[0] stderr = output[1]  print(stdout) print(stderr) 

or if want have errors , output see in console, add 2>&1 @ end of command. like:

avr-g++ -o .pioenvs\uno\frameworkarduino\hardwareserial.o -c -std=gnu++11 -fno-exceptions -fno-threadsafe-statics -g -os -wall -ffunction-sections -fdata-sections -mmcu=atmega328p -df_cpu=16000000l -darduino_arch_avr -darduino_avr_uno -darduino=10607 -i.pioenvs\uno\frameworkarduino -i.pioenvs\uno\frameworkarduinovariant .pioenvs\uno\frameworkarduino\hardwareserial.cpp 2>&1 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -