Skip to content

Commit e15f621

Browse files
committed
Fix "the input device is not a TTY" with non-interactive commands
Fixes running non-interactive commands via plain ssh (as opposed to "ssh -t"): $ ssh server /path/to/isolate-gpu -d 0 echo hello the input device is not a TTY ... by avoiding to pass "-it" to "docker run" if we don't have a terminal. We now get the expected: $ ssh server /path/to/isolate-gpu -d 0 echo hello hello
1 parent 6b0313d commit e15f621

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

isolate-gpu

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,17 @@ for group_id in "${groups_array[@]}"; do
190190
group_add_options+=(--group-add "$group_id")
191191
done
192192

193-
docker run -it --rm \
193+
EXTRA_OPTS=()
194+
195+
# Go interactive iff we have a terminal. This avoids "The input
196+
# device is not a TTY" errors when running a non-interactive session
197+
# via ssh. E.g., "ssh server isolate-gpu -d 0 make -C project-dir".
198+
if [ -t 1 ]; then
199+
EXTRA_OPTS+=(-ti)
200+
fi
201+
202+
docker run --rm \
203+
"${EXTRA_OPTS[@]}" \
194204
-u "$(id -u):$(id -g)" \
195205
"${group_add_options[@]}" \
196206
--cap-add=SYS_PTRACE \

0 commit comments

Comments
 (0)