Bazel is a build tool which coordinates builds and runs tests.

Recently I wrote some code as follow:

#include <cstdio>
#include <cstring>

#include <fcntl.h>
#include <unistd.h>

#include <sys/select.h>

int kbhit() {
  struct timeval tv;
  fd_set fds;
  tv.tv_sec = 0;
  tv.tv_usec = 0;
  select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv);
  return FD_ISSET(STDIN_FILENO, &fds);

int main(int argc, char const *argv[]) {
  char buf[1001];
  memset(buf, 0, sizeof(char) * 1001);
  while (true) {
    if (kbhit()) {
      if(nullptr != fgets(buf, 1000, stdin)) {
        int n = strlen(buf);
        printf("In:[%d][%s]\n", n, buf);
    } else {
      usleep(200 * 1000); // sleep 200 ms

This is a simple code which is used to read stdin when some input stream comes, or process something else (in usleep section).

And then, I use

bazel run //path/to/my:code

It always jump to stdin but reads nothing.

With ONE day's searching, I finally find this introduction

Bazel closes stdin, so you can't use bazel run if you want to start an interactive program or pipe data to it.