家用设备改linux,linux如何修改当前输入设备

linux如何修改当前输入设备

[复制链接]

平时都是在telnet环境远程调试,输入\输出设备是虚拟终端

[root@TR600-Plus ~]# ls -l /proc//fd

total 0

lrwx------    1 root     root            64 Mar 21 14:15 0 -> /dev/pts/0

lrwx------    1 root     root            64 Mar 21 14:15 1 -> /dev/pts/0

lrwx------    1 root     root            64 Mar 21 14:15 2 -> /dev/pts/0

现在我需要将输入、输出都重定向

输入:USB键盘  (0设备指向   /dev/input/event3)

输出:LCD屏幕 (1\2设备指向   /dev/tty0)

输出重定向我已经做到

[root@TR600-Plus nfs]# ./a.out > /dev/tty1

[root@TR600-Plus ~]# ls -l /proc//fd

total 0

lrwx------    1 root     root            64 Mar 21 14:17 0 -> /dev/pts/0

l-wx------    1 root     root            64 Mar 21 14:17 1 -> /dev/tty1

lrwx------    1 root     root            64 Mar 21 14:17 2 -> /dev/pts/0

随意敲击USB键盘按键,LCD上能显示,但仅仅是显示,它得不到程序界面任何响应。在USB键盘上Ctrl+C无法终止程序

只有在telnet的/dev/pts/0输入Ctrl+C才能终结

尝试摸索Qt的做法

运行qt程序,查阅它打开的设备

[root@TR600-Plus ~]# ls -l /proc/1405/fd

total 0

lrwx------    1 root     root            64 Mar 21 14:21 0 -> /dev/pts/0

lrwx------    1 root     root            64 Mar 21 14:21 1 -> /dev/pts/0

lrwx------    1 root     root            64 Mar 21 14:21 10 -> /dev/input/event2 触屏

lrwx------    1 root     root            64 Mar 21 14:21 11 -> /dev/input/event3 USB键盘

lrwx------    1 root     root            64 Mar 21 14:21 12 -> socket:[1336]

lrwx------    1 root     root            64 Mar 21 14:21 13 -> /dev/spidev3.0

lrwx------    1 root     root            64 Mar 21 14:21 14 -> /tmp/qtembedded-0/fonts/_12_50.qsf

lrwx------    1 root     root            64 Mar 21 14:21 2 -> /dev/pts/0

lr-x------    1 root     root            64 Mar 21 14:21 3 -> pipe:[1328]

l-wx------    1 root     root            64 Mar 21 14:21 4 -> pipe:[1328]

lr-x------    1 root     root            64 Mar 21 14:21 5 -> pipe:[1331]

l-wx------    1 root     root            64 Mar 21 14:21 6 -> pipe:[1331]

lrwx------    1 root     root            64 Mar 21 14:21 7 -> socket:[1332]

lrwx------    1 root     root            64 Mar 21 14:21 8 -> /dev/fb0

lrwx------    1 root     root            64 Mar 21 14:21 9 -> /dev/tty0

貌似Qt也没有对设备0重定向,而是直接打开新设备,我对他的做法很好奇。它应该是另成一套体系了,若按照它的做法,应该不能使用标准C库函数 比如  getchar、scanf、getchar等,这些接口都是从标准输入设备0上读取的。

我的最终目的就是能通过调用 getchar() 实现相应,

我还尝试使用   dup2  来重定向,但也不能达到效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值