问题描述
我有一个带有简单交互式命令行界面的嵌入式Linux应用程序.
I have an embedded linux application with a simple interactive command line interface.
我想从telnet(或通常的网络)访问命令行.
I'd like to access the command line from telnet (or network, in general).
但是,该过程应在电路板开启时并在唯一的情况下开始.因此,以下netcat
命令不是一个选项:
However, the process should be started when the board turns on, and in a unique instance. So, the following netcat
command is not an option:
nc -l -p 4000 -e myapp
我可以做到
nc -l -p 4000 | myapp
向myapp发送远程命令,但是这样我看不到myapp
输出.
to send remote commands to myapp, but this way I can't see myapp
output.
是否可以将两者 stdin和stdout都重定向到netcat
?
Is there any way to redirect both stdin and stdout to netcat
?
谢谢.
推荐答案
我发现通过使用bash v.> = 4.0,我可以使用coproc
:
I found that by using bash v. >= 4.0 I can use coproc
:
#!/bin/bash
coproc myapp
nc -kl -p 4000 <&"${COPROC[0]}" >&"${COPROC[1]}"
编辑
最终,我在cli库中合并了一个telnet服务器.您可以在GitHub上找到结果: https://github.com/daniele77/cli
I eventually incorporated a telnet server in my cli library. You can find the result on GitHub: https://github.com/daniele77/cli
这篇关于将进程stdin和stdout重定向到netcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!