Questions tagged [stdio]
18 questions
7
votes
3 answers
Behaviour of the backspace on terminal
This is about the behaviour of the backspace (\b) character.
I have the following C program:
int main() {
printf("Hello\b\b");
sleep(5);
printf("h\n");
return 0;
}
The output on my terminal is
Helho
with the cursor advancing to…
forumulator
- 203
- 2
- 6
7
votes
3 answers
Communicate backwards in a pipe
I have a simple pipeline:
node foo.js | node bar.js
bar.js will read from stdin to get data from foo.js.
But what I want to do is ensure that bar.js gets one of the last messages from foo.js before foo.js decides it's OK to exit. Essentially I want…
Alexander Mills
- 9,330
- 19
- 95
- 180
4
votes
1 answer
Determine if producer is outpacing consumer in pipeline
If I have:
node foo.js | node bar.js
is there a way to determine if there is a queue in between them that's building up?
in other words if the producer is outpacing the consumer w.r.t. stdio?
Alexander Mills
- 9,330
- 19
- 95
- 180
2
votes
1 answer
Additional file descriptor for debugging and piped output (logging, metrics, etc)
For a bash script project, I write human-readable log info to stdout/stderr. Additionally, I want to write formatted metrics to a third stream that will be discarded by default but can be redirected for piped processing. Is the approach doing this…
Mazzen
- 23
- 3
1
vote
1 answer
Which commands need prefixing by "stdbuf"?
When I have a long running Bash pipeline of commands, and I often can't see any signs of life due to I/O buffering. I found online that buffering can be disabled using stdbuf. An example shown here is:
tail -f access.log | stdbuf -oL cut -d aq aq…
user2153235
- 379
- 1
- 11
1
vote
1 answer
Did fwrite/fread(3) offer different "multiple items" behavior on different platforms historically?
The fread(3) and fwrite(3) have an extra parameter for a variable number of items. So a typical write often has a hardcoded count when all it has is a char buffer to begin with e.g. fwrite(data, len, 1, stdout).
What is the point of this parameter?…
natevw
- 174
- 8
1
vote
2 answers
How to read server stdout and continue only after message is outputted
Say I have a simple Node.js server like:
const http = require('http');
const server = http.createServer((req,res) => res.end('foobar'))
server.listen(3000, () => {
console.log(JSON.stringify({"listening": 3000}));
});
and then with…
user393961
1
vote
2 answers
Appending both stdout and stderr to file
I have this:
nohup_ntrs(){
nohup_file="$HOME/teros/nohup/stdio.log"
mkdir -p "$(dirname "$nohup_file")";
echo " ------------- BEGIN $(date) -------------- " >> "$nohup_file"
nohup "$@" &>> "$nohup_file"
echo " ------------- END $(date)…
Alexander Mills
- 9,330
- 19
- 95
- 180
1
vote
1 answer
Writing and Executing Program to behave like console
I have written a set of programs with the intent of using a radio transmitter-receiver (NRF24L01) to connect two devices as if they were connected via a serial interface.
Currently, i am able to send bash commands in one direction, lets say from…
fisherdog1
- 13
- 2
0
votes
1 answer
How to pipe STDIO from a thread process to /dev/null?
I am trying to run Plarium Play with wine, but have encountered an odd issue. When trying to launch it from a regular desktop entry, I get this JavaScript error:
This does not happen if I launch from the terminal.
If I try and launch it from a…
TheLabCat
- 95
- 10
0
votes
1 answer
Unexpected behavior of linux specific getline() function in C
#include
#include
#define MAXLEN 1024
void reverse(FILE *, FILE *);
int main(int argc, char ** argv)
{
...
reverse(fptr, stdout);
...
return 0;
}
void reverse(FILE * instream, FILE * outstream)
{
char ** buf;
…
arka
- 193
- 5
0
votes
1 answer
How `stdio` recognizes whether the output is redirected to the terminal or a disk file?
#include
#include
int main(void)
{
printf("If I had more time, \n");
write(STDOUT_FILENO, "I would have written you a shorter letter.\n", 43);
return 0;
}
I read that
I/O handling functions (stdio library functions)…
arka
- 193
- 5
0
votes
0 answers
How to access kallsyms from outside operational system (edk2 SMM driver)?
I'm using EDK2 to write a System Management Mode (SMM) driver. I think it uses "Pure C", given the fact that I'm not able to use standard C library like stdio. Even if I #include it throws me an error undefined reference to "fopen" when I…
Allan Almeida
- 13
- 2
0
votes
0 answers
How to escape standard input when "cat f - g"
man cat shows the following example:
cat f - g
Output f's contents, then standard input, then g's
contents.
How do you escape the standard input and proceed to output the 2nd file 'g'?
MattP
- 111
- 4
0
votes
1 answer
*nix shell: How to disable pipe buffering for ALL pipes in a command?
I want every pipe to be unbuffered, so I don't have to type stdbuf -oL for every piped command. When concocting commands with multiple pipes, it would be nice if there was a environment variable or something to enable it globally or at least for the…
Aaron Frantisak
- 101