I have a C program that reads accelerometer data continously via i2c. Whenever the orientation of the tablet has changed, it outputs a new line to stdout.
Now, I want to be able to use that output in a bash script to change the rotation of the screen.
Now, the problem is this: When I view the output of the program in bash, the program is outputting the changes line by line. When I redirect the output to a file, output is written continously in the file, but when I try to pipe the output, nothing is happening.
Here is the C program:
#include <stdio.h>
int main(int argc, char *argv[])
{
int changed;
char *orientation;
while (1) {
/* Read data from i2c, check for change in orientation */
if (changed) {
fprintf(stdout, "%s\n", orientation);
fflush(stdout);
changed = 0;
}
}
exit(0);
}
And here is my trial in bash:
#!/bin/bash
# This does not work, xrandr is not called.
./i2c-rotation | xargs xrandr --orientation
# This is working
#./i2c-rotation > output
xargs xrandr --orientation <(./i2c-rotation;)