Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 使用命名管道创建读/写环境_Bash_Redirect_System Verilog - Fatal编程技术网

Bash 使用命名管道创建读/写环境

Bash 使用命名管道创建读/写环境,bash,redirect,system-verilog,Bash,Redirect,System Verilog,我使用的是RedHat EL 4。我正在使用Bash 3.00.15 我正在写SystemVerilog,我想模仿stdin和stdout。我只能使用文件,因为环境中不支持普通stdin和stdout。我想使用命名管道来模拟stdin和stdout 我了解如何使用mkpipe创建to_sv和from_sv文件,以及如何在SystemVerilog中打开和使用它们 通过使用“cat>to_sv”,我可以将字符串输出到SystemVerilog模拟。但这也会输出我在shell中输入的内容 我想,如果

我使用的是RedHat EL 4。我正在使用Bash 3.00.15

我正在写SystemVerilog,我想模仿stdin和stdout。我只能使用文件,因为环境中不支持普通stdin和stdout。我想使用命名管道来模拟stdin和stdout

我了解如何使用mkpipe创建to_sv和from_sv文件,以及如何在SystemVerilog中打开和使用它们

通过使用“cat>to_sv”,我可以将字符串输出到SystemVerilog模拟。但这也会输出我在shell中输入的内容

我想,如果可能的话,一个单一的外壳,它的行为几乎像一个UART终端。我键入的任何内容都直接输出到“to_sv”,而写入“from_sv”的内容都会打印出来

如果我在这件事上完全错了,那么一定要提出正确的方法!非常感谢你


Nachum Kanovsky

您可能希望使用
exec
,如:

exec > to_sv
exec < from_sv
exec>to_sv
exec<来自_sv

参见第19.1节和第19.2节。在

编辑中:可以输出到命名管道,并从同一终端中的另一管道读取。您还可以使用
stty-echo
禁用要回显到终端的按键

mkfifo /tmp/from
mkfifo /tmp/to
stty -echo
cat /tmp/from & cat > /tmp/to
使用此命令时,您写入的所有内容都将转到
/tmp/to
,并且不会回显,写入
/tmp/from
的所有内容都将回显

更新:我找到了一种方法,可以将输入到/tmp/的每个字符一次发送到一个。使用以下命令代替
cat>/tmp/to

while IFS= read -n1 c;
do  
   if [ -z "$c" ]; then 
      printf "\n" >> /tmp/to; 
   fi; 
   printf "%s" "$c" >> /tmp/to; 
done

您可以使用
tail-f/tmp/from&
而不是
cat/tmp/from&
(至少在Mac OS X 10.6.7上,如果我
echo
多次到
/tmp/from
,这可以防止死锁)

根据Lynch的代码:

# terminal window 1
(
rm -f /tmp/from /tmp/to
mkfifo /tmp/from
mkfifo /tmp/to
stty -echo
#cat -u /tmp/from & 
tail -f /tmp/from & 
bgpid=$!
trap "kill -TERM ${bgpid}; stty echo; exit" 1 2 3 13 15
while IFS= read -n1 c;
do  
  if [ -z "$c" ]; then 
    printf "\n" >> /tmp/to
  fi; 
  printf "%s" "$c" >> /tmp/to
done
)

# terminal window 2
(
tail -f /tmp/to & 
bgpid=$!
trap "kill -TERM ${bgpid}; stty echo; exit" 1 2 3 13 15
wait
)

# terminal window 3
echo "hello from /tmp/from" > /tmp/from

我刚刚很快就试过了。它似乎还不适合我。我尝试的是“exec>到_sv&”,然后是“execto_sv作业也从另一个shell退出。如果可能的话,我希望在一个shell中同时执行两个方向。就像UART终端一样。我输入的内容不应该被回音。我相信在cat>/tmp/a解决方案中,所有字符都会回显。@user832745我更新了我的答案。起初我没有正确理解你需要什么。可能是因为我从来没有使用过真正的终端,只有终端模拟器。这件事对我来说也没什么意义,可能是因为我有软件背景,而不是电子/硬件背景。现在我希望我的答案和你描述的一样。这非常有帮助!非常感谢。它现在正在工作。可以不缓冲地发送字符吗?目前,我在终端中键入的内容(转到/tmp/to)只有在我按enter键时才会发送信件。我怎样才能让每个按键在没有缓冲的情况下运行?很难找到一种方法一次发送一个按键
cat
dd
seam等待
\n
,即使使用
read-n1 c一次只能读取一个字符;回显“$c”
,它不处理空格或换行符。我再查一下看能不能找到。可能是一个诅咒软件?或者像minicom这样的终端也可以。我已经更新了我的解决方案,将每个字符一次发送到输出。