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常用模块之sys
    python操作zip文件
    python的os模块
    [Python模块学习]用qrcode模块生成二维码
    os模块os.walk() 方法和os.path.join()的简单使用
    python操作redis详解
    成员变量和局部变量
    类和对象 引用属性和方法举例
    Java String字符串/==和equals区别,str。toCharAt(),getBytes,indexOf过滤存在字符,trim()/String与StringBuffer多线程安全/StringBuilder单线程—— 14.0
    泛型--面向对象8
  • 原文地址:https://www.cnblogs.com/sshbit/p/13225656.html
Copyright © 2011-2022 走看看