0
我使用下面的命令重定向的sed将一个tmp文件的输出:重定向sed的输出(来自grep的管道)到一个文件中的C程序
grep --include=*.txt -A 3 -rnw abx/ -F -e 'simple' | sed -n 's#.*/\([^/]*\.txt\).*"\([^"]*\)*"[[:space:]]*,[[:space:]]*/\*[[:space:]]*col[[:space:]]*\*/#\1\n\2#p' > tmp
,如果它的输出重定向tmp中在终端中使用,但在C程序中,没有任何内容写入'tmp'。
C程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char cmd[1028];
strcpy (cmd, "grep --include=*.txt -A 3 -rnw abx/ -F -e 'simple' | sed -u -n 's#.*/\\([^/]*\\.txt\\).*\"\\([^\"]*\\)*\"[[:space:]]*,[[:space:]]*/\\*[[:space:]]*col[[:space:]]*\\*/#\\1\\n\\2#p' > tmp");
system (cmd);
return 0;
}
编辑: 实施例文本文件:
simple =
"sik", /* fill */
"trauma", /* type */
"hui", /* col */
此文件存储在ABX /。
你可以打印字符串,看看你在做什么。您也可以检查系统调用的返回值。 – mch
系统调用返回值为0.我编辑了这个问题。 – Shahzad
可能重复的[重定向输出到C文件](http://stackoverflow.com/questions/8516823/redirecting-output-to-a-file-in-c) – Cyrus