我想从stdin流中读取.使用read()或fgets()从stdin流中读取是否有任何区别.
我用fgets附加以下两段代码并读取.使用fgets,我可以使用java程序轻松地编写和读取c程序.随着读写,我的java程序挂起等待C程序的输出,而不是来.
我只是读了一行保持它在buf并附加A到它.
Java程序能够与以下程序通信,该程序与fgets和puts一起使用.
#include <stdio.h>
#include <string.h>
#define SIZE 200000
main()
{
int rc;
int df;
int i;
char buf[SIZE];
for(i=0;i<=120000;i++) {
memset(buf,'\0',SIZE);
if(!fgets(buf,SIZE-1,stdin))
continue;
strcat(buf,"A_A_A_A_A_A_A");
puts(buf);
}
Run Code Online (Sandbox Code Playgroud)
}
但没有read()和write()
main()
{
int rc;
int df;
int i;
char buf[32768];
rc = fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
//rc = fcntl(fileno(stdout), F_SETFL, O_NONBLOCK);
FILE *fp;
for (;;)
{
int rc=-1;
memset(buf,'\0',32768);
//rc = fread(buf,5, 1, stdin);
rc = read(fileno(stdin),buf,32768);
if (rc > 0)
{
strcat(buf,"B_B_B_B_B_B_B_B_B");
write(fileno(stdout),buf,strlen(buf));
}
}
Run Code Online (Sandbox Code Playgroud)
}
有人可以说出原因.我仍然觉得很难弄明白
我有两个问题
1)如何从java.runtime库调用unix shell来运行这样的命令
进程p = Runtime.getRuntime().exec(命令);
猫别名>偏见
2)如何从java读取和写入来自unix管道的稳定数据流.我是否必须将所有系统调用(例如开放读取写入管道)
我基本上想要复制这个命令
猫别名>偏见
稳定的数据流将来自java程序偏向而不是cat别名.
我想在右边漂浮两个div.最右边的div有可变文本,所以我希望左边的div继续向左移动但是坚持使用可变数据的右边div.我什么时候浮动:右边两个div替换正确的div.
<div class="wrap">
<div class ="left">static data<div>
<div class ="right">variable data<div>
<div class="wrap">
css
.left{
float:right;
width:69%;
display:block;
}
.right{
float:right;
width:28%;
display:block;
}
.wrap{
width:100%;
}
Run Code Online (Sandbox Code Playgroud)
右边和左边的div还有一些div,但没有任何类.我该如何处理这个问题.左侧div在显示时接管右侧div.
谢谢,