stdin

Best way to read binary file c++ though input redirection

此生再无相见时 提交于 2019-12-18 07:00:19
问题 I am trying to read a large binary file thought input redirection ( stdin ) at runtime, and stdin is mandatory. ./a.out < input.bin So far I have used fgets. But fgets skips blanks and newline. I want to include both. My currentBuffersize could dynamically vary. FILE * inputFileStream = stdin; int currentPos = INIT_BUFFER_SIZE; int currentBufferSize = 24; // opt unsigned short int count = 0; // As Max number of packets 30,000/65,536 while (!feof(inputFileStream)) { char buf[INIT_BUFFER_SIZE];

In Linux, why is there a global /dev/stdin file for all processes?

左心房为你撑大大i 提交于 2019-12-18 05:59:20
问题 Shouldn't the standard input for different process unique? If so, shouldn't the path of the stdin file be like /dev/pid/stdin instead of a global /dev/stdin ? Does anyone have ideas about this? 回答1: /dev/stdin is unique because it is a symbolic link to /proc/self/fd/0 /proc/self is a symbolic link only seen by your running process to its process-id The /proc filesystem is a virtual (not real ) filesystem which has the ability to show a different view to each process. Further reading: Linux

/dev/stdin with herestring

限于喜欢 提交于 2019-12-18 04:55:08
问题 I would like a Bash script that can take input from a file or stdin, much like grep , for example $ cat hw.txt Hello world $ grep wor hw.txt Hello world $ echo 'Hello world' | grep wor Hello world $ grep wor <<< 'Hello world' Hello world all works beautifully. However with the following script read b < "${1-/dev/stdin}" echo $b It fails if using a herestring $ hw.sh hw.txt Hello world $ echo 'Hello world' | hw.sh Hello world $ hw.sh <<< 'Hello world' /opt/a/hw.sh: line 1: /dev/stdin: No such

where is stdin defined in c standard library?

℡╲_俬逩灬. 提交于 2019-12-18 04:45:17
问题 I found this line in stdio.h : extern struct _IO_FILE *stdin; Based on this 'extern' keyword, i assume this is just a declaration. I wonder where is stdin defined and initialized? 回答1: It's defined in the source code of your C library. You typically only need the headers for compilation, but you can find the source code for many open-source standard libraries (like glibc). In glibc, it's defined in libio/stdio.c as like this: _IO_FILE *stdin = (FILE *) &_IO_2_1_stdin_; Which is in turn

How do I chain stdout in one child process to stdin in another child in C?

主宰稳场 提交于 2019-12-18 04:23:12
问题 I've been messing around in C trying to figure out how to do this. Let's say I have my main program, the parent process. The parent creates three child processes, each of which will eventually run programs (but that's not important right now). What I'd like to do is make it so that the first child's stdout will be received by the second child's stdin. The second child's stdout will then be received by the third child's stdin. The parent process's stdin/stdout aren't messed with at all. So far

Redirect Python standard input/output to C# forms application

落爺英雄遲暮 提交于 2019-12-18 03:01:47
问题 I apologize if this is a duplicate question, I searched a bit and couldn't find anything similar - I have a Python library that connects to my C# application via a socket in order to allow simple Python scripting (IronPython isn't an option right now for a couple of reasons). I would like to create a Windows Forms control that would be basically a graphical front-end for the Python interpreter, so that the user could run the interpreter without having to have a separate console window open. I

Nodejs Child Process: write to stdin from an already initialised process

雨燕双飞 提交于 2019-12-17 22:13:16
问题 I am trying to spawn an external process phantomjs using node's child_process and then send information to that process after it was initialized, is that possible? I have the following code: var spawn = require('child_process').spawn, child = spawn('phantomjs'); child.stdin.setEncoding = 'utf-8'; child.stdout.pipe(process.stdout); child.stdin.write("console.log('Hello from PhantomJS')"); But the only thing I got on the stdout is the initial prompt for phantomjs console. phantomjs> So it seems

Flush/Clear System.in (stdin) before reading

只愿长相守 提交于 2019-12-17 21:13:11
问题 At work, we have 5 RFID readers attached to a PC running Linux. The readers are all recognized as keyboards and send their input (what they read form the Chip) as an key-input-event sequence. To be able to tell which reader send what sequence, I'm doing a raw-read over /dev/input/XX and get their input this way. The problem with this is, that the send keyboard-events generated by the RFID readers are still "in" stdin and when I try to read from System.in via Scanner (input should be generated

rewinding stdin in a bash script

这一生的挚爱 提交于 2019-12-17 20:29:51
问题 Is there a simple way to "rewind" /dev/stdin inside my bash script which already read all or some portion from the input pipe? Application: I wrote a simple MDA that in part 1, reads a single email from fetchmail line by line, like so: while read -a linA; do echo -e "$[++linenum]:\t${#linA[@]},${linA[*]}" > /dev/null # verbose [ "${linA[0]}" = "Date:" ] && unset linA[0] && mailDate="${linA[*]}" [ "${linA[0]}" = "Subject:" ] && unset linA[0] && mailSubject="${linA[*]}" [ "$mailSubject" =

read() from stdin doesn't ignore newline

我的梦境 提交于 2019-12-17 19:52:24
问题 I am using the following conditional statement to read from standard input. if ((n = read(0,buf,sizeof(buf))) != 0) When inputting data from standard input, generally the user presses enter when done. But read() considers '\n' as input too in which case n = 1 and the conditional doesn't evaluate to false. Is there a way to make the conditional evaluate to false when the user presses enter (without entering anything) on standard input apart from checking the contents of buf. Is there any other