stdout

Linux: Capture output of an already running process ( in pure C! )

ε祈祈猫儿з 提交于 2019-12-03 08:37:36
My situation is the following: I've got a lot of small gizmos ( pretty close to routers, not exactly but anyway that's irrelevant) ; they are running a bare-bones MIPS-based Linux distro. To control them, one can telnet there ( thru serial port ) and issue commands to an interactive bash-like shell which then writes back some output. The shell's input and output are both attached to /dev/ttyAS0. Now, I'd like to automate all of this, i.e. write a program that will run inside the gizmo, be a small server listening on some port, and which would pass on any command to the said shell, capture

Read from pipe line by line in C

社会主义新天地 提交于 2019-12-03 06:53:13
How can I separate the lines which are coming from a pipe. In the pipe there is this text: HALLO:500\n TEST:300\N ADAD ADAWFFA AFAGAGAEG I want to separate the lines from the pipe because i want to save the values in variables. Here is my c code: #include <stdio.h> #include <stdlib.h> #define BUFFERSIZE 1 int main(int argc, char **argv){ unsigned char buffer[BUFFERSIZE]; FILE *instream; int bytes_read=0; int buffer_size=0; buffer_size=sizeof(unsigned char)*BUFFERSIZE; /* open stdin for reading */ instream=fopen("/dev/stdin","r"); /* did it open? */ if(instream!=NULL){ /* read from stdin until

How to redirect STDOUT and STDERR to a variable

孤街浪徒 提交于 2019-12-03 06:52:24
I want to redirect STDERR and STDOUT to a variable. I did this. close(STDOUT); close(STDERR); my $out; open(STDOUT, ">>", \$out); open(STDERR, ">>", \$out); for(1..10) { print "print\n"; # this is ok. warn "warn\n"; # same system("make"); # this is lost. neither in screen nor in variable. } The problem with system . I want the output of this call to be captured too. Are you seeking to capture the output in a variable? If so, you have use backticks or qx{} with appropriate redirection. For example, you could use: #/usr/bin/env perl use strict; use warnings; # Ensure we have a way to write

C and Erlang: Erlang Port example

久未见 提交于 2019-12-03 06:48:26
Disclaimer: The author of the question has an average knowledge of Erlang and a basic knowledge of C. I am reading the Interoperability Tutorial User Guide now. I have successfully compiled the complex.c example and it works with the Erlang Port without any problems. However, I would like to understand how the actual C code works. I understand it in general: in the example it reads 2 bytes from the standard input and checks the first byte. Depending on the first byte it calls either foo or bar function. This is the limit of my understanding of it right now. So, if we take both erl_comm.c : /*

What is the difference between writing to STDOUT and a filehandle opened to “/dev/tty”?

喜欢而已 提交于 2019-12-03 06:33:44
What are the differences between this two examples? #!/usr/bin/perl use warnings; use 5.012; my $str = "\x{263a}"; open my $tty, '>:encoding(utf8)', '/dev/tty' or die $!; say $tty $str; close $tty; open $tty, '>:bytes', '/dev/tty' or die $!; say $tty $str; close $tty; # ------------------------------------------------------- binmode STDOUT, ':encoding(utf8)' or die $!; say $str; binmode STDOUT, ':bytes' or die $!; say $str; The difference is that you are writing to two distinct and (from Perl's and your program's point of view) independent file handles. The first one is a file handle opened to

node.js child_process.spawn no stdout unless 'inherit'

心不动则不痛 提交于 2019-12-03 06:17:12
I'm trying to capture the stdout from a spawn ed child_process in node.js (0.10.29). Right now I'm just trying with ping The following code doesn't print (but does ping) var exec = require('child_process').exec; var spawn = require('child_process').spawn; var util = require('util') var ping = spawn('ping', ['127.0.0.1'], {stdio: 'pipe'}); ping.stdout.on('data', function(data){ util.print(data); }) ping.stderr.on('data', function(data){ util.print(data); }) If I change stdio: 'pipe' to stdio: 'inherit' and get rid of the stdout/stderr hooks like so: var ping = spawn('ping', ['127.0.0.2'],

Asynchronously redirect stdout/stdin from embedded python to c++?

一笑奈何 提交于 2019-12-03 05:38:27
I am essentially trying to write a console interface with input and output for an embedded python script. Following the instructions here , I was able to capture stdout: Py_Initialize(); PyRun_SimpleString("\ class StdoutCatcher:\n\ def __init__(self):\n\ self.data = ''\n\ def write(self, stuff):\n\ self.data = self.data + stuff\n\ import sys\n\ sys.stdout = StdoutCatcher()"); PyRun_SimpleString("some script"); PyObject *sysmodule; PyObject *pystdout; PyObject *pystdoutdata; char *string; sysmodule = PyImport_ImportModule("sys"); pystdout = PyObject_GetAttrString(sysmodule, "stdout");

What is the “sys.stdout.write()” equivalent in Ruby?

十年热恋 提交于 2019-12-03 04:27:38
As seen in Python, what is the sys.stdout.write() equivalent in Ruby? In Ruby, you can access standard out with $stdout or STDOUT . So you can use the write method like this: $stdout.write 'Hello, World!' or equivalently: STDOUT.write 'Hello, World!' $stdout is a actually a global variable whose default value is STDOUT . You could also use puts , but I think that is more analogous to python's print . puts "Hello, world!" or print - because it buffered. puts (or print if you don't want a newline ( \n ) automatically appended). Here is a one liner for both writing and reading to/from stdin and

Python. Redirect stdout to a socket

不羁的心 提交于 2019-12-03 02:59:36
I run my script on "A" computer, then i connect to "A" computer from "B" computer through my script. I send my message to computer "A" and my script run it with 'exec()' instruction. I want to see result of execution my message on "A" computer, through socket on "B" computer. I try to change sys.stdout = socket_response but have a error: "Socket object has no attribute write()" So, how can i redirect standart output (for print or exec()) from "A" computer to "B" computer through socket connection." It will be some kind of 'python interpreter' into my script. SORRY, I CAN'T ANSWER MY OWN

How can I stream data from a managed assembly to a native library and back again?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 02:52:19
How can I stream data (text) from a managed assembly to a native library and stream data (text) back to the managed assembly? Specifically, I want to expose a System.IO.Stream of some sort on the .NET side, and ( most importantly ) a FILE * on the native side. The signature of the native method should be: FILE * foo(FILE * bar); The signature of a wrapper around the native p/invoke call should be: CustomStream foo(CustomStream bar); I do not want to use callback methods on the native side (one for getting more data and one for setting more data). I want to use a FILE * on the native side - and