[C] LINUX C 编程dup2问题
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
void get_cal(const char *arg)
{
char cmd[64];
strcpy(cmd, arg);
int pfds[2],bak_stdout;
if(pipe(pfds)==0)
{
printf("2\n");
printf("fd_11 is %d\n",pfds[1]);
printf("2.1\n");
bak_stdout=dup(1);
printf("2.1.1\n");
// close(1);
printf("2.1.1.1\n");
dup2( pfds[1], 1);
close(pfds[0]);
printf("1.2\n");
system(cmd);
close(pfds[1]);
dup2(bak_stdout,1);
}
else
printf("pipe open error!\n");
}
void read_cal(char *data)
{
char cmd[64], line[199];
*data = 0;
int pfds[2];
if(pipe(pfds)==0)
相关问答:
最近突然想自己来实现一个五子棋程序,但不知道怎么开始,自己也没学画图形函数,能在控制台下直接写吗>>>?????
控制台?比图形界面更麻烦。
http://search.download.csdn.net/search/%E4%BA%94%E5%AD%90% ......
最近在看一个用bison实现的C parser,OS是opensolaris。当用它来解析一个简单的hello.c时,出现“/usr/include/sys/va_list.h: parse error before __gnuc_va_list”。打开文件va_list.h后发现这样一行“typedef __bu ......
写了个测试程序如下
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
......
#include "stdio.h"
int main()
{
char *ch(char *, char *);
char str1[]="I am glad to meet you!";
char str2[]="Welcom to study C!";
&nb ......