zoukankan      html  css  js  c++  java
  • Linux测试程序交互实现

    void sig_handler(int signo) 
    {
        std::cout << "oops! stop!!!" << std::endl;
        _exit(0);
    }
    
    int main(int argc, char **argv)
    {
    
        PadSim pad_sim ;
        pad_sim.init(node);
    
        signal( SIGINT, sig_handler); /*注册ctrl+c 退出函数*/
        int value = system("stty erase ^H");/* 退格键不回显 */
    
        char cmd[256];
        std::cout <<"***************************************************************" << std::endl;
        std::cout <<"The command list:" << std::endl;
        std::cout << std::left << std::setw(20) << "h"
                            << " This help text
    "
    
                            << std::setw(20) << "auto"
                            << " Start: switch control mode to auto 
    "
                            << std::setw(20) << "manual"
                            << " Stop:  switch control mode to manual
    "
    
                            << std::setw(20) << "start"
                            << " Start: switch task mode start 
    "
                            << std::setw(20) << "stop"
                            << " Stop:  switch task mode to stop
    "
                            << std::setw(20) << "pause"
                            << " Pause: switch task mode to pause
    "
                            << std::setw(20) << "continue"
                            << " Pause: switch task mode to continue
    "
                            << std::setw(20) << "shutdown"
                            << " Shut down the program
    "
                            << std::flush;
        std::cout <<"***************************************************************" << std::endl;
        std::cout << "> ";
        while (std::cin.getline(cmd, sizeof(cmd))) 
        {
            std::string strCmd(cmd);
            if (strCmd == "shutdown") 
            {
                break;
            } 
            else if (strCmd == "h")
            {
                std::cout << std::left << std::setw(20) << "h"
                            << " This help text
    "
    
                            << std::setw(20) << "auto"
                            << " Start: switch control mode to auto 
    "
                            << std::setw(20) << "manual"
                            << " Stop:  switch control mode to manual
    "
    
                            << std::setw(20) << "start"
                            << " Start: switch task mode to start 
    "
                            << std::setw(20) << "stop"
                            << " Stop:  switch task mode to stop
    "
                            << std::setw(20) << "pause"
                            << " Pause: switch task mode to pause
    "
                            << std::setw(20) << "continue"
                            << " Pause: switch task mode to continue
    "
                            << std::setw(20) << "shutdown"
                            << " Shut down the program
    "
                            << std::flush;
            } 
            else if (strCmd == "auto") 
            {
                pad_sim.pad_send_message(1008);
            } 
            else if (strCmd == "manual") 
            {
                pad_sim.pad_send_message(1009);
            } 
            else if (strCmd == "start") 
            {
                pad_sim.pad_send_message(1007);
            } 
            else if (strCmd == "stop") 
            {
                pad_sim.pad_send_message(1006);
            } 
            else if (strCmd == "pause") 
            {
                pad_sim.pad_send_message(1004);
            } 
            else if (strCmd == "continue") 
            {
                pad_sim.pad_send_message(1005);
            } 
            else 
            {
                std::cerr << "Error: unknown commamd" << std::endl;
            }           
            std::cout << "> ";
        }
        std::cout << "exit " << std::endl;
        return 0;
    }
    

      

  • 相关阅读:
    python学习之列表
    python学习之数据类型
    开启python学习之路
    软件工程中的需求分析包括的主要内容
    论需求分析和数据库设计的重要性
    Android的ListView分页功能(上滑加载更多)
    设置ListView显示到最后一行
    一对一Socket简单聊天的实现
    Spring Cloud学习笔记-004
    Spring Cloud学习笔记-003
  • 原文地址:https://www.cnblogs.com/sshbit/p/13225656.html
Copyright © 2011-2022 走看看