Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: PLEASE help (me) with syntax for placings redirection to file. Pin
k505420-Feb-24 6:53
mvek505420-Feb-24 6:53 
GeneralRe: PLEASE help (me) with syntax for placings redirection to file. Pin
Mircea Neacsu20-Feb-24 6:55
Mircea Neacsu20-Feb-24 6:55 
GeneralRe: PLEASE help (me) with syntax for placings redirection to file. Pin
Salvatore Terress20-Feb-24 10:02
Salvatore Terress20-Feb-24 10:02 
GeneralRe: PLEASE help (me) with syntax for placings redirection to file. Pin
Richard MacCutchan20-Feb-24 21:45
mveRichard MacCutchan20-Feb-24 21:45 
AnswerRe: PLEASE help (me) with syntax for placings redirection to file. Pin
Richard MacCutchan19-Feb-24 21:42
mveRichard MacCutchan19-Feb-24 21:42 
QuestionRepost This is a request for C/C++ code... Pin
Salvatore Terress16-Feb-24 6:49
Salvatore Terress16-Feb-24 6:49 
AnswerRe: Repost This is a request for C/C++ code... Pin
jschell16-Feb-24 7:22
jschell16-Feb-24 7:22 
AnswerRe: Repost This is a request for C/C++ code... Pin
k505416-Feb-24 7:57
mvek505416-Feb-24 7:57 
Try using a Here Document :
Bash
[k5054@localhost]$ sudo ps
[sudo] password for k5054: 
sudo: no password was provided
sudo: a password is required
[k5054@localhost]$ cat example.cpp
 #include <iostream>
 #include <cstdio>
 #include <cstdlib>

int main()
{
    std::string userPass{"myPassword"};
    std::string command{"sudo -S ps -lf 2>/dev/null <<_EOF\n" + userPass + "\n_EOF"};
    FILE *pipe = popen(command.c_str(), "r");
    char *line = NULL;
    size_t len = 0;
    ssize_t rlen;
    while( (rlen = getline(&line, &len, pipe))  > 0) {
        line[--rlen] = '\0'; // trim trailing newline
        std::cout << line << '\n';
    }

    pclose(pipe);
    free(line);

}
[k5054@localhost]$ make example
g++ -Wall -Wextra -ggdb    example.cpp   -o example
[k5054@localhost]$ ./example 
F S UID          PID    PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
1 S root        4030    4029  0  80   0 -  4799 do_pol 11:49 pts/2    00:00:00 sudo -S ps -lf
4 R root        4031    4030  0  80   0 -  3502 -      11:49 pts/2    00:00:00 ps -lf
[k5054@localhost]$ 
You should be able to modify that for use with QProcess.
Note that if you don't redirect stderr to /dev/null, the SSH password prompt goes to wherever stderr is pointing to.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown

GeneralRe: Repost This is a request for C/C++ code... Pin
Salvatore Terress16-Feb-24 16:02
Salvatore Terress16-Feb-24 16:02 
QuestionVisual Studio Resource Editor Pin
Richard Andrew x6416-Feb-24 2:03
professionalRichard Andrew x6416-Feb-24 2:03 
AnswerRe: Visual Studio Resource Editor Pin
Mircea Neacsu16-Feb-24 2:28
Mircea Neacsu16-Feb-24 2:28 
GeneralRe: Visual Studio Resource Editor Pin
Richard Andrew x6416-Feb-24 2:51
professionalRichard Andrew x6416-Feb-24 2:51 
GeneralRe: Visual Studio Resource Editor Pin
jschell16-Feb-24 7:23
jschell16-Feb-24 7:23 
GeneralRe: Visual Studio Resource Editor Pin
Mircea Neacsu16-Feb-24 7:30
Mircea Neacsu16-Feb-24 7:30 
Questionhow to get "native window" ? Pin
Salvatore Terress11-Feb-24 8:26
Salvatore Terress11-Feb-24 8:26 
AnswerRe: how to get "native window" ? Pin
CPallini11-Feb-24 20:14
mveCPallini11-Feb-24 20:14 
GeneralRe: how to get "native window" ? Pin
Richard MacCutchan12-Feb-24 5:13
mveRichard MacCutchan12-Feb-24 5:13 
GeneralRe: how to get "native window" ? Pin
k505412-Feb-24 3:44
mvek505412-Feb-24 3:44 
GeneralRe: how to get "native window" ? Pin
k505412-Feb-24 7:14
mvek505412-Feb-24 7:14 
AnswerRe: how to get "native window" ? Pin
jschell13-Feb-24 4:45
jschell13-Feb-24 4:45 
GeneralRe: how to get "native window" ? Pin
Richard MacCutchan14-Feb-24 4:23
mveRichard MacCutchan14-Feb-24 4:23 
GeneralRe: how to get "native window" ? Pin
Dave Kreskowiak14-Feb-24 4:37
mveDave Kreskowiak14-Feb-24 4:37 
AnswerRe: How to implement sudo -S and -ps options Pin
k505414-Feb-24 12:57
mvek505414-Feb-24 12:57 
GeneralRe: How to implement sudo -S and -ps options Pin
Richard MacCutchan15-Feb-24 21:02
mveRichard MacCutchan15-Feb-24 21:02 
GeneralRe: How to implement sudo -S and -ps options Pin
jschell15-Feb-24 11:41
jschell15-Feb-24 11:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.