linux下简单交互式shell程序,linux下用c函数实现简单的交互式shell.pdf

. 专业 整理 .

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define BUF_LEN 1024

#define MAX_FILE_NAME 256

#define MAX_PROCESS_NUM 2

#define MAX_ARGC 10

#define BOOL int

#define TRUE 1

#define FALSE 0

#define DELIM " |<>"

. 学 习帮手 .

. 专业 整理 .

enum

{

E_OPEN = 0,

E_PIPE,

E_DUP2,

E_EXECVP,

E_FORK

};

enum

{

FIRST = 0,

SECOND

};

BOOL get_std_file(char *pos_std, char **std_file)

. 学 习帮手 .

. 专业 整理 .

{

if (!pos_std)

return FALSE;

*pos_std = '\0';

*std_file = strtok(pos_std + 1, DELIM);

if (*std_file)

return TRUE;

return FALSE;

}

BOOL get_cmd_args(char *str, char **args)

{

int i = 0;

if (!str)

return FALSE;

if (!(args[i++] = strtok(str, DELIM)))

return FALSE;

while((args[i++] = strtok(NULL, DELIM)));

. 学 习帮手 .

. 专业 整理 .

return TRUE;

}

int main(int argc, char *argv[])

{

char buf[BUF_LEN];

char *first[MAX_ARGC];

char *second[MAX_ARGC];

char *stdin_file;

char *stdout_file;

char *pos;

char *pos_stdin;

char *pos_stdout;

char *pos_pipe;

. 学 习帮手 .

. 专业 整理 .

int i;

int pfd[2];

int fd;

pid_t pids[MAX_PROCESS_NUM];

pid_t pid;

while(1)

{

pos_stdin = NULL;

pos_stdout = NULL;

pos_pipe = NULL;

buf[0] = '\0';

printf("akaedu@caihui-desktop:%s#", getcwd(buf, BUF_LEN));

. 学

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值