Standard input and output units in Fortran 90?

If you have a Fortran 2003 compiler, the intrinsic module iso_fortran_env defines the variables input_unit, output_unit and error_unit which point to standard in, standard out and standard error respectively. I tend to use something like #ifdef f2003 use, intrinsic :: iso_fortran_env, only : stdin=>input_unit, & stdout=>output_unit, & stderr=>error_unit #else #define stdin 5 #define stdout 6 … Read more

Redirecting stdout to file nodejs

I solved this problem the following way: var access = fs.createWriteStream(‘/var/log/node/api.access.log’); process.stdout.write = process.stderr.write = access.write.bind(access); Of course you can also separate stdout and stderr if you want. I also would strongly recommend to handle uncaught exceptions: process.on(‘uncaughtException’, function(err) { console.error((err && err.stack) ? err.stack : err); }); This will cover the following situations: process.stdout.write … Read more

How to test a function’s output (stdout/stderr) in unit tests

One thing to also remember, there’s nothing stopping you from writing functions to avoid the boilerplate. For example I have a command line app that uses log and I wrote this function: func captureOutput(f func()) string { var buf bytes.Buffer log.SetOutput(&buf) f() log.SetOutput(os.Stderr) return buf.String() } Then used it like this: output := captureOutput(func() { … Read more

How to overwrite stdout in C

It’s not manipulating stdout — it’s overwriting the characters which have already been displayed by the terminal. Try this: #include <stdio.h> #include <unistd.h> static char bar[] = “=======================================” “======================================>”; int main() { int i; for (i = 77; i >= 0; i–) { printf(“[%s]\r”, &bar[i]); fflush(stdout); sleep(1); } printf(“\n”); return 0; } That’s pretty close … Read more

Python 2.x – Write binary output to stdout?

Which platform are you on? You could try this recipe if you’re on Windows (the link suggests it’s Windows specific anyway). if sys.platform == “win32”: import os, msvcrt msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) There are some references on the web that there would/should be a function in Python 3.1 to reopen sys.stdout in binary mode but I don’t … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)