Skip to content

Read ashyncronous and write back eventually #93

@marriusco

Description

@marriusco

how do I read output from a ping or ssh command;

        char out[256]={0};
        char err[256]={0};
        struct subprocess_s subprocess;
        char *args[4]={0,0,0,0};
        args[0] = "/usr/bin/ssh";
        args[1] = "[email protected]";
        char *env[]={"PATH=$PATH","/usr/bin", nullptr};
        int r =subprocess_create_ex(args,
                                     subprocess_option_enable_async,
                                     env, &subprocess);
        if(r==0)
        {
            FILE* p_stdin = subprocess_stdin(&subprocess);
            while(1)
            {
                subprocess_read_stdout(&subprocess, out, 255);
                if(out[0])
                    std::cout << out << "\n";
                subprocess_read_stderr(&subprocess, err, 255);
                if(out[0])
                    std::cout << err << "\n";
                if(_command.empty()==false){
                    fwrite(_command.c_str(), (unsigned)_command.length(), 1, p_stdin);
                    _command.clear();
                }
            }
        }

Catches nothing while the shell prints

[email protected]'s password:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions