0

I need tty interactive on onboot of linuxkit.

Now, setsid -w agetty -a root -L 38400 ttyS0 vt100 is working. But I want to run a specific program. Is there a way?


Thanks to "Mahdy Mirzade" for reply,

$ setsid sh -c 'exec ls <> /dev/tty2 >&0 2>&1'

This works pretty well, but It can't control the tty.

$ setsid sh -c 'exec sh -c "echo hello > /dev/tty" <> /dev/tty10>&0 2>&1'

(error message) cannot create /dev/tty: Inappropriate ioctl for device

Therefore, it is impossible to operate a program that receives user input through tty. Is there any way to solve this?

user212942
  • 197
  • 3
  • 18

1 Answers1

1

Try passing sh -c to your command:

$ setsid sh -c 'exec ls <> /dev/tty2 >&0 2>&1'
Mahdy Mirzade
  • 331
  • 3
  • 10
  • Unfortunately it doesn't work. "Usage: agetty [options] ,... []" – user212942 Aug 07 '21 at 04:01
  • @user212942 edited my post, worked and output on tty2, but not sure why you're using `agetty`, but `agetty` is also a program, your command is already running `agetty`, to run other porgram you'll need to run sh to execute it or running a program with std output after `setsid`. – Mahdy Mirzade Aug 07 '21 at 04:13
  • Actually I didn't quite understand setsid and agetty. This method works fine! thank you :) – user212942 Aug 07 '21 at 06:16
  • This works pretty well, but It can't control the tty. setsid sh -c 'exec sh -c "echo hello > /dev/tty" <> /dev/tty10>&0 2>&1' cannot create /dev/tty: Inappropriate ioctl for device Therefore, it is impossible to operate a program that receives user input through tty. Is there any way to solve this? – user212942 Aug 09 '21 at 05:09
  • @user212942 I believe you need to pass your input to your program using `stdin` or standard input, like when `stdout` is usable when you store it like `VAR=$(ls)`, you may also insert your queries to your specified program, before running in the first place using `--stdin`, but there is also an article that might help you more about user input: https://ryanstutorials.net/bash-scripting-tutorial/bash-input.php – Mahdy Mirzade Aug 09 '21 at 07:00
  • Unfortunately, it is difficult because the program was not made by me. – user212942 Aug 09 '21 at 08:03
  • @user212942 Maybe repost your new issue with new title? because it's marked green and people might not see it that often? - My answer is that I don't know how it's done but there is always who knows this, we need to show it to him. – Mahdy Mirzade Aug 09 '21 at 08:46
  • Okay Thank you :) – user212942 Aug 09 '21 at 09:09