stdout

How to redirecting “stdout” to a Label widget?

﹥>﹥吖頭↗ 提交于 2019-12-05 09:52:52
I am trying to redirect stdout to a Label widget. The goal is to "print" into the Label all the Python prints that are in my script. But when I click on BUTTON1 nothing happens... Here is my code: from Tkinter import * import sys import tkMessageBox class App: def __init__(self, master): self.frame = Frame(master, borderwidth=5, relief=RIDGE) self.frame.grid() class IORedirector(object): def __init__(self,TEXT_INFO): self.TEXT_INFO = TEXT_INFO class StdoutRedirector(IORedirector): def write(self,str): self.TEXT_INFO.config(text=str) self.TEXT_HEADER = self.text_intro = Label(self.frame, bg=

Delphi - Capture stdout and stderr output from statically linked MSVC++ compiled DLL

久未见 提交于 2019-12-05 09:45:57
I have been trying to capture stdout and stderr output from a DLL compiled in MSVC++ that my Delphi app statically links to, but so far have been unsuccessful. procedure Test; var fs: TFileStream; begin fs := TFileStream.Create('C:\temp\output.log', fmCreate or fmShareDenyWrite); SetStdHandle(STD_OUTPUT_HANDLE, fs.Handle); SetStdHandle(STD_ERROR_HANDLE, fs.Handle); dllFunc(0); // Writes to stdout in MSVC++ console app, but not here // fs.Length is always zero fs.Free; end; Thought I was on the right track, but it does not work. Is SetStdHandle() enough? Is TFileStream the right thing to use

Printing a line at the bottom of the console/terminal

落爺英雄遲暮 提交于 2019-12-05 09:33:42
Using Python, I would like to print a line that will appear on the last visible line on the console the script is being ran from. For example, something like this: Would this be able to be done? Martijn Pieters The easiest way is to use effbot.org's Console module : import Console c = Console.getconsole() c.text(0, -1, 'And this is the string at the bottom of the console') By specifying -1 for the second (line) argument you are addressing the last line of the console. Because the Console module only works on Windows, to get this to work on UNIX terminals as well, you should take a look at the

Python standard idiom to set sys.stdout buffer to zero doesn't work with Unicode

旧巷老猫 提交于 2019-12-05 08:42:44
When I'm writing sysadmin scripts in Python, the buffer on sys.stdout that effects every call to print() is annoying, because I don't want to wait for a buffer to be flushed and then get a big chunk of lines at once on the screen, instead I want to get individually lines of output as soon as new output is generated by the script. I don't even want to wait for newlines so see the output. An often used idiom to do this in python is import os import sys sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0) This worked fine for me for a long time. Now I noticed, that it doesn't work with Unicode.

Use Python to write CSV output to STDOUT

偶尔善良 提交于 2019-12-05 08:25:13
问题 I know I can write a CSV file with something like: with open('some.csv', 'w', newline='') as f: How would I instead write that output to STDOUT? 回答1: sys.stdout is a file object corresponding to the program's standard output. You can use its write() method. Note that it's probably not necessary to use the with statement, because stdout does not have to be opened or closed. So, if you need to create a csv.writer object, you can just say: import sys spamwriter = csv.writer(sys.stdout) 来源: https

C# console application stdin/stdout redirection

十年热恋 提交于 2019-12-05 08:16:54
I have an interesting (read: frustrating) problem kicking off a console application from a C# WPF app and redirecting its stdin and stdout. It is mostly up and working but I seem to end up not getting some data from stdout as soon as I start redirecting stdin. I'll clarify with an example. If I don't set hStdInput in the STARTUPINFO structure, when I start the child process I receive the following: MongoDB shell version: 2.2.0 connecting to: test local:PRIMARY> Once I set hStdInput however, I just get this: MongoDB shell version: 2.2.0 connecting to: test I know that the BackgroundWorker

windows console program stdout is buffered when using pipe redirection

陌路散爱 提交于 2019-12-05 07:27:26
i have a long run server program(say, program A) which is written in QT/c++. the program is not so stable so i decide to write a python script to restart it if it crashes. the problem is that the program may started fail(if i gave it an in-use port), print the error and then just hang there without quitting, so i must monitor the stdout of the program and kill it on failed startup. this is a piece of my final code (well, in fact this is ok, you can just ignore it): self.subp = subprocess.Popen( r'.\A.exe -server %d' % portnum, stdout=subprocess.PIPE, bufsize=1) for line in iter(self.subp

multithreading issue with wx.TextCtrl (or underlying GTK+)

假如想象 提交于 2019-12-05 06:13:26
问题 I am developing a GUI to launch an external long-term running background program. This background program can be given input command via stdin and use stdout and stderr to keep printing out output and error messages. I use a wx.TextCtrl object inside the GUI to give input and print output. My current code is as follows, which is mainly inspired by the "how to implemente a shell GUI window" post: wxPython: how to create a bash shell window? However, my following code uses "buffer previous

Can an Adobe AIR Application run via the command line output to console?

梦想与她 提交于 2019-12-05 05:29:46
I have an AIR application that takes command-line arguments via onInvoke. All is good, but I cannot figure out how to print some status messages back to the user (to stdout / console, so to speak). Is it possible? Even a default log file for traces would be fine, but I can't find any info about it anywhere. Do I need to create my own log file? Now that'd be silly. Take a look at CommandProxy . It is a low level wrapper around your AIR application that lets you send command from AS3 back to the proxy for communicating with the underlying OS. You should be able to add a means of writing to the

Bash, stdout redirect of commands like scp

荒凉一梦 提交于 2019-12-05 04:39:02
I have a bash script with some scp commands inside. It works very well but, if I try to redirect my stdout with " ./myscript.sh >log ", only my explicit echos are shown in the "log" file. The scp output is missing. if $C_SFTP; then scp -r $C_SFTP_USER@$C_SFTP_HOST:$C_SOURCE "$C_TMPDIR" fi Ok, what should I do now? Thank you scp is using interactive terminal in order to print that fancy progress bar. Printing that output to a file does not make sense at all, so scp detects when its output is redirected to somewhere else other than a terminal and does disable this output. What makes sense,