stdin

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 : /*

How to extract tar archive from stdin?

孤人 提交于 2019-12-03 06:30:18
问题 I have a large tar file I split . Is it possible to cat and untar the file using pipeline. Something like: cat largefile.tgz.aa largefile.tgz.ab | tar -xz instead of: cat largefile.tgz.aa largfile.tgz.ab > largefile.tgz tar -xzf largefile.tgz I have been looking around and I can't find the answer. I wanted to see if it was possible. 回答1: Use - as the input file: cat largefile.tgz.aa largefile.tgz.ab | tar zxf - Make sure you cat them in the same order they were split. If you're using zsh you

Golang read from pipe reads tons of data

我怕爱的太早我们不能终老 提交于 2019-12-03 05:59:16
问题 I'm trying to read an archive that's being tarred, streaming, to stdin, but I'm somehow reading far more data in the pipe than tar is sending. I run my command like this: tar -cf - somefolder | ./my-go-binary The source code is like this: package main import ( "bufio" "io" "log" "os" ) // Read from standard input func main() { reader := bufio.NewReader(os.Stdin) // Read all data from stdin, processing subsequent reads as chunks. parts := 0 for { parts++ data := make([]byte, 4<<20) // Read 4MB

How to read from stdin or from a file if no data is piped in Python?

折月煮酒 提交于 2019-12-03 05:53:10
问题 I have a CLI script and want it to read data from a file. It should be able to read it in two ways : cat data.txt | ./my_script.py ./my_script.py data.txt —a bit like grep , for example. What I know: sys.argv and optparse let me read any args and options easily. sys.stdin let me read data piped in fileinput make the full process automatic Unfortunately: using fileinput uses stdin and any args as input. So I can't use options that are not filenames as it tries to open them. sys.stdin.readlines

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");

PowerShell's pipe adds linefeed

蹲街弑〆低调 提交于 2019-12-03 05:01:27
I'm trying to pipe a string into a program's STDIN without any trailing linefeeds (unless that string itself actually ends in a linefeed). I tried googling around, but I only found people trying to print to the console without a trailing linefeed, in which case Write-Host takes a parameter -NoNewLine . However, to pipe it on to another program, I need Write-Output or similar which doesn't have such a parameter. Now it seems like Write-Output isn't even the problem: Z:\> (Write-Output "abc").Length 3 But as soon as I pipe it to another program and read the string there, I get an additional

How to read lines from stdin (*in*) in clojure

孤人 提交于 2019-12-03 04:06:53
问题 I am writing my first clojure program, and want to read lines from stdin. When I try this: (doall (map #(println %) (line-seq *in*))) I get this exception: Exception in thread "main" java.lang.ClassCastException: clojure.lang.LineNumberingPushbackReader cannot be cast to java.io.BufferedReader (test.clj:0) I get the same results in version 1.0 and 1.1 So how do I convert *in* into a seq I can iterate over? I would have thought that this is common enough that *in* itself would be iterable, but

Fastest way for line-by-line reading STDIN?

陌路散爱 提交于 2019-12-03 03:49:03
问题 I'm looking for the most time-efficient way to read STDIN line-by-line. The first line is the number of conditions to test. All the following lines are conditions (strings) with a maximum of 100 000 characters. I have already tried the following (plus result for 4 times 90 000 characters: Scanner with a while-loop (7255 ms) Scanner sc = new Scanner(System.in); int numberOfLines = Integer.parseInt(sc.nextLine()); long start = 0; int i = 1; while (i<=numberOfLines){ start = System

Faster way to write image to Process.StandardInput.BaseStream

有些话、适合烂在心里 提交于 2019-12-03 03:40:28
Im trying to send a lot of desktop captured images to an encoders (FFmpeg) stdin. The following code example works. the CaptureScreen() function provides an image in 5-10 ms. If I save the image in a MemoryStream it takes almost no time. But I can only save 1 image every 45 ms to proc.StandardInput.BaseStream. public void Start(string bitrate, string buffer, string fps, string rtmp, string resolution, string preset) { proc.StartInfo.FileName = myPath + "\\ffmpeg.exe"; proc.StartInfo.Arguments = "-f image2pipe -i pipe:.bmp -vcodec libx264 -preset " + preset + " -maxrate " + bitrate + "k

Standard Input for Unsigned Character

喜夏-厌秋 提交于 2019-12-03 01:21:56
问题 I am trying to send unsigned characters through a program, and I would like to be able to get the numbers through standard input (ie std::cin). For example when I type 2 I would like it send ☻ (unsigned char 2). when I use the code: std::cout << "Enter values: "; { unsigned char d; unsigned char e = 2; std::cin >> d; WriteFile(file, &d, 1, &written, NULL); std::cout << "d= " << d << "\n"; std::cout << "e= " << e; } I get Enter values: 2 d=2 e=☻ Can anyone tell me why d is being interpreted