dup

    -1热度

    1回答

    我正在写一份dup()函数(我正在为Linux api学习一本书)。 我有一个名为temp.txt的文件,它包含一行以下字符串:Hello, World。 下面是代码: #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> #includ

    0热度

    1回答

    我想用管道制作一个简单的外壳。 我觉得我几乎做到了,但它并没有回到主体。 我认为exec没有完成。 下面是我的代码的一部分。 我解析了如下定义的结构块的命令。 符号类型5表示它具有| 。 当我运行这个程序, this is result image.当我不使用管道,它返回并打印>再次,但是当我使用管道它不。 typedef struct Command { char *file;

    1热度

    1回答

    在我的ruby on rails应用程序中,我试图在克隆后保存模型时出现问题。我有以下模型。 class Company < ApplicationRecord has_many :employees end class Employee < ApplicationRecord belongs_to :company has_one :user end

    0热度

    1回答

    我在做一个程序,它将接收3个参数,./a.out abc,其中a和c是列号,b和操作数由行分隔。 当它的真实再现stdin其他没有结果。 例子: $ ./a.out 1 > 2 $ 5:2:1:6 5:2:1:6 $ ./a.out 2 = 4 $ 1:2:3:4 $ 我试着在我的第一个版本,doint管道,并从标准输入读取数据时切需要它,但我的问题是,我失去了输入。 现在我试图从

    0热度

    2回答

    我写在C小贝壳在Linux上运行之后。因为有很多参与了DUP,我想问一下,如果有一种方法来打印里面是什么位置0。例如,如果我叫DUP2(FILE_NAME,0)是有没有办法打印FILE_NAME所以我可以使用它进行调试?

    -1热度

    2回答

    该代码需要2个文件并将结果放入第三个文件。 它这样做很好,但是引起我关注的是最后一个printf没有打印到屏幕上。第一个打印很好。这告诉我,我没有正确恢复标准输出? int main (int argc, char *argv[]) { char *join[4]={"cat", "file1.txt","file2.txt", 0}; int id, fd, status;

    0热度

    2回答

    所以我试图使用dup()将标准输出重定向到文件。 int save_fd; save_fd=dup(1); //saves the current stdout close(1); //closes stdout dup2(file.txt, 1);//redirect output to file.txt //output goes to file.txt dup2(save_fd

    0热度

    1回答

    我写过Zsh模块。在那里我有一个内置函数映射到Zsh命令。这个函数可以复制其标准输入文件描述符: /* Duplicate standard input */ oconf->stream = fdopen(dup(fileno(stdin)), "r"); 然后,线程派生,其获得oconf结构。在该线程,我做的: errno = 0; /* Read e.g. 5 characters,

    0热度

    2回答

    我有这个小程序: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/wait.h> int main() { int orig = 1; for (int i = 0; (i != 3) && orig; ++i) { orig = orig && fork()

    0热度

    1回答

    我正在研究示例程序,以了解管道和分叉如何工作。在我的非常基本的实现,在我的子进程,我关闭0和重复管道的读端,使文件描述符0现在是我管的读取结束。 从我的父进程中,我写出了一个字符串,并在我的子进程中,我读取字符串使用cin作为cin本质上是我的管道读取结束,我观察到的是完整的字符串不打印出来,我似乎无法理解为什么! #include <iostream> #include <unistd.h>