stdout

Copy STDOUT to file without stopping it showing onscreen

The program I am making is designed to be run unattended, because of this I have redirected the stdout and stderr streams to a log file. While this works without any problems, while I am still making and debugging the software I would like it to show on the screen as well. Is this possible? To redirect the streams I have used System.se...

How can I capture Rake output when invoked from with a Ruby script?

I am writing a web-based dev-console for Rails development. In one of my controller actions, I am calling Rake, but I am unable to capture any of the output that Rake generates. For example, here is some sample code, from the controller: require 'rake' require 'rake/rdoctask' require 'rake/testtask' require 'tasks/rails' require 'string...

Error when redirecting stdout and stderr of powershell script

The script runs fine when stdout/stderr are not redirected. When I add both stderr and stdout redirection, I getg the following error: How can I avoid it? % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 19.4M 0 0 ...

Shell/Bash Command to get nth line of STDOUT

Is there any bash command that will let you get the nth line of STDOUT? That is to say, something that would take this $ ls -l -rw-r--r--@ 1 root wheel my.txt -rw-r--r--@ 1 root wheel files.txt -rw-r--r--@ 1 root wheel here.txt and do something like $ ls -l | magic-command 2 -rw-r--r--@ 1 root wheel files.txt I realize this wo...

Redirecting native dll stdout/stderr from within C#

Hi... I'm trying to redirect the output of a third-party native dll which outputs to stdout/stderr from within C#. The output of both stdout and stderr should go to a log file. Here's my idea (x2 for two streams): Create an AnonymousPipeServerStream Get the pipe's handle via _outServer.SafePipeHandle.DangerousGetHandle() Use P/Invoke...

Should I output warnings to STDERR or STDOUT?

I'm making a script that handles a predefined set of data, outputting to a file. I want to pop up a warning when one datum (which is always "Regular" in every set that I've had access to) is different stating that this value is unhandled (since I don't know how it affects the data). Should I output this warning to stderr or stdout? ...

VCL forms application writing to stdout

My company has a large Windows application with a document-object model: open application, open a file, make some changes, save, close. I'm attempting to cut the GUI off of the top and create a console application that accepts some parameters, opens a file, does something useful, saves, closes the file, and terminates. Because there is...

Writing unicode strings via sys.stdout in Python

Assume for a moment that one cannot use print (and thus enjoy the benefit of automatic encoding detection). So that leaves us with sys.stdout. However, sys.stdout is so dumb as to not do any sensible encoding. Now one reads the Python wiki page PrintFails and goes to try out the following code: $ python -c 'import sys, codecs, locale; ...

Binary stdin and stdout

I'm looking to write a pair of utilities that read in a newline separated list of integers on stdin and output their binary (4 byte) equivalent to stdout, and vice versa. My first thought was a simple bash/linux command that would do this, but I was unable to find one. My second thought was to do this in C++, but I can't figure out how...

Using getchar() after read()

Hi I am using raw.c for keyboard capture. Following code finds when an arrow key/ esc is pressed. At the same time I want to read whole words that user inputs and these should be shown on stdout as well. char pp = 0; char p = 0; while( (i = read(0, &c, 1)) == 1) { if (pp == 033 && p == 0133 && (c &= 255) == 0102) /* DOWN */ break; if (c...

How to redirect all console output to a Swing JTextArea/JTextPane with the right encoding?

Hi, I've been trying to redirect System.out PrintStream to a JTextPane. This works fine, except for the encoding of special locale characters. I found a lot of documentation about it (see for ex. mindprod encoding page), but I'm still fighting with it. Similar questions were posted in StackOverFlow, but the encoding wasn't addressed as...

Can I send STDOUT and STDERR to a log file and also to the screen in Win32 Perl?

I've searched the Internet and have found some good solutions for teeing STDOUT to 2 different places. Like to a log file and also to the screen at the same time. Here's one example: use IO::Tee; my $log_filename = "log.txt"; my $log_filehandle; open( $log_filehandle, '>>', $log_filename ) or die("Can't open $log_filename for append...

capturing stderr and stdout from an already running process in solaris

I've got a process that is currently running (arserverd) that was started by user "remedy". I am able to log in as this user. I would like to capture stderr and stdout without restarting the process. Is this possible? ...

Force another program's standard output to be unbuffered using Python

A python script is controlling an external application on Linux, passing in input via a pipe to the external applications stdin, and reading output via a pipe from the external applications stdout. The problem is that writes to pipes are buffered by block, and not by line, and therefore delays occur before the controlling script receiv...

Can I capture stdout/stderr separately and maintain original order?

I've written a Windows application using the native win32 API. My app will launch other processes and capture the output and highlight stderr output in red. In order to accomplish this I create a separate pipe for stdout and stderr and use them in the STARTUPINFO structure when calling CreateProcess. I then launch a separate thread for ...

Segmentation fault only when I redirect stdout to /dev/null ?

I've got a C++ unit test that produces useful output to stderr, and mostly noise (unless I'm debugging) to stdout, so I'd like to redirect the stdout to /dev/null. Curiously enough, doing this seems to cause a segmentation fault. Is there any reason why code might seg fault with "> /dev/null" and run fine otherwise? The output is prod...

[C++] CreateProcessWithLoginW - Redirecting STDOUT

What I would like is to have the process start but have the input and output all be in the same console. if(CreateProcessWithLogonW(user,domain, pass, LOGON_WITH_PROFILE, NULL, cmd, 0, 0, 0, &sa, &pe)) { printf("[~] Process spawned with PID %X\n", pe.dwProcessId); } else { printf("[!] Failed to create process. Error Code: %X\n", GetL...

using ruby popen wrapped in a shell script

I finished my short file for a homework assignment which uses IO.popen("command").readlines to grab the STDOUT of that command. However, I need to write a shell script to wrap my ruby file in. No problem, but somehow putting it in the shell script makes readlines hang. ruby script.rb foo example > example.out this works script.sh foo...

How to ask bash to wait for a result and send a SIGKILL when it get it ?

I want to use zbarcam but after reading a barcode, it doesn't stop. $ zbarcam | xvkbd -file - -window emacs EAN-13:6941428130969 CODE-128:3096140900557 Do you know how I can tell bash to kill zbarcam after printing on the stdout the first \n ? ...

Redirect stdout+stderr on c# windows service

I've wrote a windows service in C# using ServiceBase helper. During its execution some procedures on an external native DLL are called. Annoyingly, those procedures write to stdout and/or stderr in a uncontrolled manner as no sources are given for this DLL. Is it possible to redirect those outputs from the C# service to a log file? Reg...