草庐IT

stdin_reader

全部标签

linux - 为什么在 bash 中的 while read 循环中重定向 stdin?

考虑以下示例脚本:#!/bin/shdo_something(){echo$@return1}catsample.textThisisasampletextItservesnootherpurposeEOFcatsample.text|whilereadarg1arg2arg3arg4arg5;doret=0do_something"$arg1""$sarg2""$arg3""$arg4""$arg5"将stdout重定向为文件描述符3的输入的目的是什么?至少在Bash中,省略它似乎没有任何区别。如果它在bash以外的任何其他shell中执行,它是否有任何影响?更新对于那些想知道这是从

c - stdio 文件描述符(stdin、stdout、stderr)是否仅通过#include'ing <stdio.h> 打开?

在C语言中将整数转换为字符串时,我对包含stdio.h感到有点恼火——这不会使二进制文件因不必要的文件描述符和其他代码而膨胀吗?或者仅当您在代码中使用标准io文件描述符stdout、stdin或stderr时才打开流,例如printf、scanf、fprintf?如果我的代码只使用snprintf(3)可能还可以?我拥有的最接近的现成解决方案是将整数转换为strfromd(3)的doublefloat,格式字符串不超过小数点。bhuwansahni在HowtoconvertintegertostringinC?中提供了一个很好的自己动手解决方案我不知道如何使用(链接无效)itoa、_i

c - stdio 文件描述符(stdin、stdout、stderr)是否仅通过#include'ing <stdio.h> 打开?

在C语言中将整数转换为字符串时,我对包含stdio.h感到有点恼火——这不会使二进制文件因不必要的文件描述符和其他代码而膨胀吗?或者仅当您在代码中使用标准io文件描述符stdout、stdin或stderr时才打开流,例如printf、scanf、fprintf?如果我的代码只使用snprintf(3)可能还可以?我拥有的最接近的现成解决方案是将整数转换为strfromd(3)的doublefloat,格式字符串不超过小数点。bhuwansahni在HowtoconvertintegertostringinC?中提供了一个很好的自己动手解决方案我不知道如何使用(链接无效)itoa、_i

python - 如何用 `stdin=sys.stdin` 重现 `stdin=PIPE` ?

我有以下代码可以完全按预期工作:fromsubprocessimportPopenprocess=Popen(["/bin/bash"],stdin=sys.stdin,stdout=sys.stdout,stderr=sys.stderr,)process.wait()我可以交互式地使用bash、tabworks等。但是,我想控制发送到stdin的内容,所以我希望以下内容起作用:importosimportsysfromsubprocessimportPopen,PIPEfromselectimportselectprocess=Popen(["/bin/bash"],stdin=P

python - 如何用 `stdin=sys.stdin` 重现 `stdin=PIPE` ?

我有以下代码可以完全按预期工作:fromsubprocessimportPopenprocess=Popen(["/bin/bash"],stdin=sys.stdin,stdout=sys.stdout,stderr=sys.stderr,)process.wait()我可以交互式地使用bash、tabworks等。但是,我想控制发送到stdin的内容,所以我希望以下内容起作用:importosimportsysfromsubprocessimportPopen,PIPEfromselectimportselectprocess=Popen(["/bin/bash"],stdin=P

C 编程 : How do I read terminal input if piping from stdin?

所以,我正在尝试编写一个c程序来读取通过管道传输到程序中的输入(通过标准输入),但我还需要能够从终端读取输入(所以我显然无法从标准输入读取它).我该怎么做?我正在尝试像这样打开/dev/tty的另一个文件句柄:intsee_more(){charresponse;intrd=open("/dev/tty",O_RDWR);FILE*reader=fdopen(rd,"r");while((response=getc(reader))!=EOF){switch(response){case'q':return0;case'':return1;case'\n':return-1;}}}但这

C 编程 : How do I read terminal input if piping from stdin?

所以,我正在尝试编写一个c程序来读取通过管道传输到程序中的输入(通过标准输入),但我还需要能够从终端读取输入(所以我显然无法从标准输入读取它).我该怎么做?我正在尝试像这样打开/dev/tty的另一个文件句柄:intsee_more(){charresponse;intrd=open("/dev/tty",O_RDWR);FILE*reader=fdopen(rd,"r");while((response=getc(reader))!=EOF){switch(response){case'q':return0;case'':return1;case'\n':return-1;}}}但这

linux - 在 while read (stdin) 循环后暂停 bash 脚本

我正在制作一个通过管道(stdin)获取输入的脚本,如(other_command|my_script)。但是,在我阅读了整个标准输入后,我需要暂停脚本并等待用户按下回车键。这是一个示例脚本。#!/bin/bashif[[-t0]];thenecho"Nostdin"elseecho"Gotstdin"whilereadinput;doecho$inputdonefiecho"Pressentertoexit"read它是这样工作的;$echotext|./scriptGotstdintextPressentertoexit$它跳过了我最后的read。然而;$./scriptNostd

linux - 在 while read (stdin) 循环后暂停 bash 脚本

我正在制作一个通过管道(stdin)获取输入的脚本,如(other_command|my_script)。但是,在我阅读了整个标准输入后,我需要暂停脚本并等待用户按下回车键。这是一个示例脚本。#!/bin/bashif[[-t0]];thenecho"Nostdin"elseecho"Gotstdin"whilereadinput;doecho$inputdonefiecho"Pressentertoexit"read它是这样工作的;$echotext|./scriptGotstdintextPressentertoexit$它跳过了我最后的read。然而;$./scriptNostd

linux - 我可以以非规范的方式从 stdin 读取吗?

有什么方法可以从non-canonicalmode中的stdin中读取吗?在Linux下?非规范输入意味着在stdin上对read()的调用应在用户键入时立即返回,这不是默认行为,正如可以通过尝试看到的那样://Createabufferletmutbuffer:[u8;1]=[0];//Loopsovertheinputfromstdin,onecharacteratimewhileio::stdin().read(&mutbuffer).unwrap()>0{println!("{:?}",buffer);}此代码等待用户按return打印buffer的内容。期望的行为是在用户键入