• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ read_command函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中read_command函数的典型用法代码示例。如果您正苦于以下问题:C++ read_command函数的具体用法?C++ read_command怎么用?C++ read_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了read_command函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: cria_pipe

void cria_pipe(){
    int pipe(int fd[2]);

    int fd[2];
    int fd1[2];
    pipe(fd);
    pipe(fd1);

    printf("Contador: %i\n", cont);

    if (fork() != 0){
        waitpid(-1,status,0);
        if(cont>0){
            close(fd1[1]);
            dup2(fd1[0], 0);
            read(fd1[0], &i, sizeof(i));
            close(fd1[0]);
            printf("Valor de i pai: %i\n",i);
            printf("%c\n",str[i]);
            //se encontrar algum espaço ou | passa para a próxima posição de str
            if(str[i] != '\n' && (str[i] == '|' || str[i] == ' '))
                while(str[i] != '\n' && (str[i] == '|' || str[i] == ' '))
                    i++;
            read_command(str, command, parameters);
        }
        //processo pai executa esses comandos
        waitpid(-1,status,0);
        close(fd[1]); //o processo 1 precisa ler o pipe
        dup2(fd[0], 0); //configura a saída padrão para fd[0]
        execvp(command, parameters);
        close(fd[0]); //este descritor de arquivo não é mais necessário
        }
    else{
        //o processo filho executa estes comandos
        read_command(str, command, parameters);

        if(cont>0){
            close(fd1[0]);
            dup2(fd1[1],1);
            write(fd1[1], &i, sizeof(i));
            close(fd1[1]);
        }
        //pipe de entrada
        close(fd[0]);
        dup2(fd[1],1);
        printf("Valor de i filho: %i\n",i);
        execvp(command, parameters);
        close(fd[1]);
    }
}
开发者ID:UNIFESP-SO,项目名称:SIMPLE_SHELL,代码行数:50,代码来源:shell_forks.c


示例2: main

int main(int argc, char** argv)
{
	if(argc < 2) error("Uso: server porta\n");
	buffer = (DATA*) malloc(DEFAULT_SIZE);
	char command_str[16];
	char address_str[16];
	IPV4_Address address;
	SOCKET socket;

	socket = create_socket(IPV4,TCP,DEFAULT);
	address = ipv4_address("",atoi(argv[1]));
	bind_socket(socket,(Address*)&address);
	man_socket = listen_socket(
	socket,(struct sockaddr*)&address);

	is_terminated = FALSE;
	puts("Waiting for players...");
	forever{
		//memset(buffer,' ',DEFAULT_SIZE);
		read(man_socket,buffer,DEFAULT_SIZE);
		strcpy(command_str,buffer->command);
		strcpy(address_str,buffer->address);
		printf("command: %s",command_str);
		read_command(command_str,address_str);	
		if(is_terminated == TRUE) break;
	}
	
	strcpy(buffer->results,"Terminated");
	write(man_socket,buffer,DEFAULT_SIZE);
	close(man_socket);
	close(socket);

	return 0;
}
开发者ID:efforia,项目名称:libsockets,代码行数:34,代码来源:server.c


示例3: main

int main(int argc, char *argv[])
{
    read_history(history_file);
    load_tab_completion();
    signal(SIGINT, &sighandler); // Don't die on sigint

    FILE * fd_sig = fdopen(5, "r"); // get signals to read from fd5
    if(!fd_sig)
        exit(0);

    FILE * fd_out = fdopen(6, "w"); // output lines on fd6
    if(!fd_out)
        exit(0);

    if(argc > 1) // load the prompt if available
        prompt = argv[1];

    do 
    {
        read_command(fd_sig, fd_out);
    } while(command);
 
    free(command);
    command = NULL;
    fclose(fd_sig);
    fclose(fd_out);

    write_history(history_file);
    return 0;
}
开发者ID:sbbowers,项目名称:Coterminous-Conflux,代码行数:30,代码来源:readline_wrapper.cpp


示例4: proc

void proc(void)
{
    int status,i;
    char *command = NULL;
    char **parameters;
	char prompt[MAX_PROMPT];
    parameters = malloc(sizeof(char *)*(MAXARG+2));
    buffer = malloc(sizeof(char) * MAXLINE);
    if(parameters == NULL || buffer == NULL)
    {
        printf("Rshell error:malloc failed.\n");
        return;
    }
	//arg[0] is command
	//arg[MAXARG+1] is NULL
    while(TRUE)
    {
        type_prompt(prompt);
        if(-1 == read_command(&command,parameters,prompt))
			continue;
		if(builtin_command(command,parameters))
			continue;
        if(fork()!=0)
        {
            waitpid(-1,&status,0);
        }
        else
        {
            execvp(command,parameters);
        }
    }
}
开发者ID:czn73126,项目名称:rshell,代码行数:32,代码来源:rshell.c


示例5: while

void ForkWrapper::run()
{
	int result = 0;
	const int debug = 0;

	while(!done)
	{
		if(debug) printf("ForkWrapper::run %d this=%p parent_fd=%d child_fd=%d\n", 
			__LINE__, this, parent_fd, child_fd);

		result = read_command();



		if(debug) printf("ForkWrapper::run %d this=%p result=%d command_token=%d\n", 
			__LINE__, this, result, command_token);

		if(!result && command_token == EXIT_CODE) 
			done = 1;
		else
		if(!result)
		{
			handle_command();
		}
	}
}
开发者ID:Cuchulain,项目名称:cinelerra,代码行数:26,代码来源:forkwrapper.C


示例6: read_and_execute_command

static void
read_and_execute_command(void)
{
	int ret;
	char *command_line, *command, *next_command;

	command = command_line = read_command();

	do {
		next_command = strchr(command, ';');
		if (next_command != NULL) {
			*next_command = '\0';
			next_command++;
		}

		strip_unneeded_whitespace(command, 1024);
		if (strlen(command) > 0) {
			ret = execute_command(command);
			if (ret)
				g_warning("Command finished with error.");
		}

		command = next_command;

	} while (command);

	free(command_line);
}
开发者ID:DanielAeolusLaude,项目名称:ardour,代码行数:28,代码来源:smfsh.c


示例7: process

static void process(ErlDrvData handle, ErlIOVec *ev) {
  spidermonkey_drv_t *dd = (spidermonkey_drv_t *) handle;
  char *data = ev->binv[1]->orig_bytes;
  char *command = read_command(&data);
  if (strncmp(command, "ij", 2) == 0) {
    char *call_id = read_string(&data);
    int thread_stack = read_int32(&data);
    if (thread_stack < 8) {
      thread_stack = 8;
    }
    thread_stack = thread_stack * (1024 * 1024);
    int heap_size = read_int32(&data) * (1024 * 1024);
    dd->vm = sm_initialize(thread_stack, heap_size);
    send_ok_response(dd, call_id);
    driver_free(call_id);
  }
  else {
    js_call *call_data = (js_call *) driver_alloc(sizeof(js_call));
    call_data->driver_data = dd;
    call_data->args = ev->binv[1];
    driver_binary_inc_refc(call_data->args);
    ErlDrvPort port = dd->port;
    unsigned long thread_key = (unsigned long) port;
    driver_async(dd->port, (unsigned int *) &thread_key, (asyncfun) run_js, (void *) call_data, NULL);
  }
  driver_free(command);
}
开发者ID:jonte,项目名称:erlang_js,代码行数:27,代码来源:spidermonkey_drv.c


示例8: ft_minishell

int				ft_minishell(t_env *e)
{
	int			len;

	prompt(e);
	while ((len = read(e->fd, e->buf, READ_SIZE)) > 0)
	{
//printf("%d %d %d %d %d %d %d %d\n", e->buf[0], e->buf[1], e->buf[2], e->buf[3], e->buf[4], e->buf[5], e->buf[6], e->buf[7]);
		if (KEYPAD(e) || K_SUPPR(e) || CTRL_C(e))
			keypad_command(e);
		else if (COPY_KEY(e))
			copy_command(e);
		else if (CTRL_D(e))
		{
			if (*e->hist->cmd == '\0')
				break ;
		}
		else
			read_command(len, e->buf, e);
		if (!SHFT_KEY(e) && !CT_SH_KEY(e) && e->cpy.cpy != 0)
			rewrite_command(e);
		ft_memset(e->buf, 0, len);
	}
	return (len);
}
开发者ID:gbourgeo,项目名称:42projects,代码行数:25,代码来源:ft_minishell.c


示例9: myshell

int myshell(char *args[], int size){
	FILE *fp;
	char command[100];
	char *argv[1000];
	char s[1000];

	if(size == 0){//必须有一个参数
		printf("myshell:没有参数\n");
		return false;
	}

	fp = fopen(args[0], "r");
	if(fp == NULL){
		printf("打开文件失败\n");
		return false;
	}
	while(!feof(fp)){
		//逐行读取指令
		size = read_command(command, argv, fp);
		//判断是否已经读取到文件末尾
		if(size == -1) break;
		//调用指令
		backstage(command, argv, size);
		//释放内存
		clear_command(argv, size);
	}
	fclose(fp);
	return 1;

}
开发者ID:000ddd00dd0d,项目名称:A-mini-bash,代码行数:30,代码来源:myshell_ins.c


示例10: main

int main(){ //主函数
	char command[100];
	char *args[1000];
	int size, i;
	char value[1050];
	char shellname[1050];

	//初始化,增加环境变量
	getcwd(first, 999); //获取当前目录
	strcpy(value, "shell=");
	strcpy(shellname, first);
	strcat(shellname, "/myshell");
	strcat(value, shellname);
	putenv(value);

	while(true){
		type_prompt();	//输出命令提示符
		//读取指令
		size = read_command(command, args, stdin);
		//分词并调用指令
		backstage(command, args, size);
		//释放内存
		clear_command(args, size);
	}
}
开发者ID:000ddd00dd0d,项目名称:A-mini-bash,代码行数:25,代码来源:myshell.c


示例11: repl

void repl() {
  SqlParser parser;
  while (true) {
    std::string command = read_command();
    std::string::size_type first_space = command.find_first_of(" ");
    std::string fst_token = first_space == string::npos ? command : command.substr(0, first_space);
    capitalize(&fst_token);

#ifdef MAIN_DBG
    Utils::info("[REPL] execute \"" + command +"\"");
#endif
    if (fst_token.compare("QUIT") == 0 || fst_token.compare("EXIT") == 0) {
      return;
    } else if (fst_token.compare("PURGE") == 0) {
      BufferManager &bm = BufferManager::get_instance();
      bm.purge();
      std::cout << "Purge has been done" << std::endl;
    } else if (fst_token.compare("BMST") == 0) {
      std::cout << "BufferManager state:" << std::endl;
      std::cout << "  Pinned pages: " + std::to_string(BufferManager::get_instance().get_pinned_page_count()) << std::endl;
      BufferManager::get_instance().print_pinned_page();
    } else if (fst_token.compare("ABOUT") == 0) {
      std::string table_name = command.substr(6);
#ifdef MAIN_DBG
      Utils::info("[REPL] 'about' was called for " + table_name);
#endif
      describe_table(table_name);
    } else {
      SqlStatement const * stmt = parser.parse(command);

      DBFacade::get_instance()->execute_statement(stmt);
      delete stmt;
    }
  }
}
开发者ID:deadok22,项目名称:shredder-db,代码行数:35,代码来源:main.cpp


示例12: simple_terminal

int simple_terminal() {
    puts("Shell is started");
    puts("===========================");
    
    while(1) {
        char command[100];
        char* parameters[100];
        int status = 0;
        
        type_porompt();
        read_command(command, parameters);
	printf("%s%s%d%d\n",parameters[0],parameters[1],parameters[2],parameters[3]);
        
        if (fork() != 0) {  //Parent
            waitpid(-1, &status, 0);
        } else {            //Child
            if (execvp(command, parameters) == -1) {
                puts("Command invalid.");
                return -1;
            }
        }
    }
    
    return 0;
}
开发者ID:fu908301,项目名称:operating-system-homework,代码行数:25,代码来源:shellex.c


示例13: main

int main(int argc, char *argv[]) {
	int status;
    	while(TRUE){
        	printf("FERNANDO&[email protected]$ ");
		str	= (char *)calloc(MAX_COM, sizeof (char));
	        command = (char *)calloc(MAX_PAR, sizeof (char));
		parameters = aloca(MAX_PAR, MAX_PAR);

	        read_commandline(str);
		if(!strcasecmp("exit\n", str)) break;
                if(!strcasecmp("\n", str)) continue;

		if(fork()==0){
	        	cont = conta_pipe(str);
			if(cont > 0){
		        cria_pipe();				
			}
			else{
				read_command(str, command, parameters);
				execvp(command, parameters);
			}
		}
		else
			wait(&status);
	}
	return 0;
}
开发者ID:UNIFESP-SO,项目名称:SIMPLE_SHELL,代码行数:27,代码来源:shell_forks.c


示例14: main

/* main program controls all the action
 */
int
main(int argc, char *argv[]) {
	int fileinput=0;
	command_t comd;
	csv_t D;

	/* first argument on commandline is the data file name */
	read_csv_file(argv[1], &D);

	/* second argument, if it exists, is file of input commands */
	if (argc==3) {
		fileinput = 1;
		reassign_input(argv[2]);
	}

	/* start the main execution loop */
	print_prompt();
	while (read_command(&comd, fileinput, D.ncols)) {
		process_line(&comd, &D);
		/* then round we go */
		print_prompt();
	}

	/* all done, so pack up and go home */
	printf("bye\n");
	return 0;
}
开发者ID:georgiah,项目名称:C-assignments,代码行数:29,代码来源:349008ass2.c


示例15: init_disp_comond

static void init_disp_comond(void)
{

	unsigned char value;
	//init pin.
	printk("[%s][%d]\r\n",__FUNCTION__,__LINE__);
	
	cs_pin = gp_gpio_request(MK_GPIO_INDEX(0,0,48,15), NULL ); //IOA15
	data_pin = gp_gpio_request(MK_GPIO_INDEX(1,0,12,0), NULL ); //IOB0
	clk_pin = gp_gpio_request(MK_GPIO_INDEX(1,0,13,1), NULL ); //IOB1

	gp_gpio_set_output(cs_pin,1,0);
	gp_gpio_set_output(data_pin,1,0);
	gp_gpio_set_output(clk_pin,1,0);

	sent_command(0x05,0x5f);
	read_command(0x05,&value);
	sent_command(0x05,0x1f);
	read_command(0x05,&value);
	sent_command(0x05,0x5f);
	read_command(0x05,&value);
	sent_command(0x2b,0x01);
	read_command(0x2b,&value);
	sent_command(0x00,0x09);
	read_command(0x00,&value);
	sent_command(0x01,0x9f);
	read_command(0x01,&value);
	
	//m-sent_command(0x03,0x60);
	sent_command(0x03,0x2e);
	read_command(0x03,&value);	
	
	//m-sent_command(0x0d,0x60);
	sent_command(0x0d,0x50);
	read_command(0x0d,&value);	
	
	//m-sent_command(0x04,0x1b);
	sent_command(0x04,0x18);
	read_command(0x04,&value);
	sent_command(0x16,0x04);
	read_command(0x16,&value);
	gp_gpio_release(cs_pin);
	gp_gpio_release(data_pin);
	gp_gpio_release(clk_pin);

}
开发者ID:go2ev-devteam,项目名称:GPCV,代码行数:46,代码来源:lcd_ILI8961_27.c


示例16: main

int main()
{
	prepare();
	reset_grid();
	while (read_command());

	return 0;
}
开发者ID:M4573R,项目名称:pc-code,代码行数:8,代码来源:postscript.cpp


示例17: interactive

void interactive(){
   while (TRUE){
    char *command;
    int i;
    char *parameters[32];
    struct timeval initial_clock;
    struct timeval final_clock;    
    int num_params;

    do{
      type_prompt();// displays prompt
      num_params = read_command(command, parameters);//get input from user and parse it into command and parameters
      if(num_params > 32){
	printf("\nOnly 32 arguments allowed.\n");
      }
    } while(num_params > 32 || num_params == -2);
    char **params = malloc((num_params + 1) * sizeof(char *));
    for(i = 0; i < num_params; i++)
      params[i] = parameters[i];
    params[i] = NULL;
    command = params[0];
    if(strcmp("exit", command) == 0) exit(4);
    if(strcmp("cd", command) == 0){
      chdir(params[1]);
      continue;
    }
    if(gettimeofday(&initial_clock, NULL) == -1) printf("\nCould not get time.\n");
    pid_t pId = fork();
    if(pId == -1){ //fork failed
      printf("Fork failed. Please try running again. %s\n", strerror(errno));
    }
    if(pId != 0){ //parent process
      int status;
      if(waitpid(pId,&status, 0) != pId) printf("waitpid failed\n");
      
      // once child process is done, print usage statistics
      if(gettimeofday(&final_clock, NULL) == -1) printf("\nCould not get time.\n");
      long seconds_elapsed = final_clock.tv_sec - initial_clock.tv_sec;
      long microseconds_elapsed = final_clock.tv_usec - initial_clock.tv_usec;
      long milliseconds_elapsed = seconds_elapsed*1000 + microseconds_elapsed*0.001;
      printf("\nWall clock time for the command to execute:\n%ld milliseconds\n", milliseconds_elapsed);
      print_statistics();
    }
    else{ //child process
      int returnnum;
      returnnum = execvp(command, params);
      if(returnnum == -1){ //error occurred during execvp
	printf("Your command didn't work: %s\n", strerror(errno));
	prev_usr_milliseconds = 0;
	prev_sys_milliseconds = 0;
	prev_stats.ru_nivcsw = 0;
	prev_stats.ru_nvcsw = 0;
	prev_stats.ru_majflt = 0;
	prev_stats.ru_minflt = 0;
      }
    }
  }
}
开发者ID:tusharnarayan,项目名称:wpi-cs,代码行数:58,代码来源:shell.c


示例18: main

int main(int argc, const char *argv[])
{
    int RUN = TRUE;
    char command[100] = "";
    char params[100] = "";

    int PIDstatus = 0;

    while (RUN) {/* Endlosschleife */
        strcpy(command, "");
        type_prompt(); /* Prompt ausgeben */

        read_command(command, params);  /* Eingabezeile von Tastatur lesen */

        if(!strcmp(command, "quit")) {
            quit_shell(&RUN);
        } else if (!strcmp(command, "version")) {
            get_version();
        } else if (!strcmp(command, "/")) {
            changedir(params);
        } else if (!strcmp(command, "help")) {
            print_help();
        } else {
            /* PIDstatus = fork(); [> Kind erzeugen <]*/
            /* if (PIDstatus < 0) {*/
            /*   printf("Unable to fork"); [> Fehlerbedingung <]*/
            /*   continue; [> Schleife wiederholen <]*/
            /* }*/
            /* if (PIDstatus > 0) {*/
            /*   waitpid (PIDstatus, &status, 0);   [> Elternprozess wartet auf Kind <]*/
            /* } else {*/
            /*   execve(command, params, 0);   [> Das Kind-Programm ausführen <]*/
            /* }*/
            PIDstatus = fork();
            if (PIDstatus < 0) {
                printf("Sorry, unable to fork");
            }
            else if (PIDstatus > 0) {
                if (params[strlen(params)-1] != '&') {
                    waitpid(PIDstatus,NULL,0);
                }
            }
            else {
                RUN = FALSE; // stop loop for this process
                if (params[strlen(params)-1] != '&') {
                    printf("\n"); // beautify output
                }
                if (execlp(command, (char const*)params, 0) == -1) {
                    printf("Programm nicht gefunden!\n");
                }
            }
        }
    }
    return 0;
}
开发者ID:HAW-AI,项目名称:BSP-A02-BRPD-C-hawsh,代码行数:55,代码来源:hawsh.c


示例19: eeprom_detect

static int eeprom_detect(void) {

	write_command(E1000_REG_EEPROM, 1);

	for (int i = 0; i < 100000 && !has_eeprom; ++i) {
		uint32_t val = read_command(E1000_REG_EEPROM);
		if (val & 0x10) has_eeprom = 1;
	}

	return 0;
}
开发者ID:klange,项目名称:ponyos,代码行数:11,代码来源:e1000.c


示例20: shell_loop

/**
 * shell main loop
 */
void shell_loop(void) {
    while (1) {
        init();
        if (read_command() == -1) {
            break;
        }
        parse_command();
        //print_command();
        execute_command();
    }
}
开发者ID:RyeZhu,项目名称:mini-shell,代码行数:14,代码来源:parse.c



注:本文中的read_command函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ read_config_file函数代码示例发布时间:2022-05-30
下一篇:
C++ read_color函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap