0

I'm working on a linux pinephone script that would launch a touchpad emulator. In order to do so, I need to compare the output string of:

./TouchpadEmulator /dev/input/event2 /dev/input/event1

once I hit enter the terminal shows

max x:719 max y:1439

and the terminal remains open, without showing any command prompt, which means that the code keeps running in background.

My problem is that I'm trying to output this "max x:719 max y:1430" to some variable, some file, or as an argument for a next command.

I've tried something like

./TouchpadEmulator /dev/input/event2 /dev/input/event1 > textfile.txt

but the textfile.txt remains empty.

I've also tried

echo $(./TouchpadEmulator /dev/input/event2 /dev/input/event1)

but the terminal screen remains blank.

My guess is that since the command keeps running in background, the echo never executes, since it waits until the "./TouchpadEmulator ... " is completely executed.

Kusalananda
  • 333,661
  • 2
    Probably it's writing to STDERR, not STDOUT. Redirect just STDERR with 2> textfile.txt. Read man bash. – waltinator Jul 24 '21 at 23:18
  • 3
    It looks like it never flushes the output buffer - try stdbuf -oL ./TouchpadEmulator /dev/input/event2 /dev/input/event1 > textfile.txt to force line-buffered output – steeldriver Jul 24 '21 at 23:23
  • @waltinator This should be the general answer. – WGRM Jul 24 '21 at 23:57
  • @steeldriver WTF. Keeps on happening. It's in coreutils and i never heard/used it. Upvote for mentioning it. – WGRM Jul 24 '21 at 23:58
  • Is your issue about finding the size of the screen? This could probably be found in other ways, possibly using xrandr. Minor unrelated comment: The command is running in the foreground, not in the background. – Kusalananda Jul 25 '21 at 06:59
  • Thanx! This one worked: stdbuf -oL ./TouchpadEmulator /dev/input/event2 /dev/input/event1 > Textfile.txt – LostNavigator23 Aug 01 '21 at 18:38
  • In general, instead of editing the question or the title to indicate the problem being solved, it's better to mark the answer solving it as accepted. Ticking the "accept" checkmark tells the system the case is closed better than a note in the title, it e.g. makes the question show up with different coloring in lists. (In principle, people are supposed to write answers as answers instead of comments...) It's also possible to write an answer yourself if you find the solution via another route, but there's some mandatory delay before you can check a self-answer as accepted. – ilkkachu Aug 01 '21 at 19:26
  • anyway, this is a duplicate, there's a number of solutions to this under other questions – ilkkachu Aug 01 '21 at 19:27

1 Answers1

-1

Probably it's writing to STDERR, rather than STDOUT.

Redirect STDERR only with 2> textfile.txt.

Read man bash.

waltinator
  • 4,865
  • It's more likely that it's actually writing to standard output, but that since the process isn't done and since it's not flushing the output explicitly, the output does not appear. The standard error stream is never buffered in the same way. – Kusalananda Jul 25 '21 at 06:41