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

C / C++ / MFC

 
GeneralRe: purpose of parameter value of -1 ? Pin
Salvatore Terress10-Feb-24 6:14
Salvatore Terress10-Feb-24 6:14 
GeneralRe: purpose of parameter value of -1 ? Pin
Richard MacCutchan10-Feb-24 21:23
mveRichard MacCutchan10-Feb-24 21:23 
AnswerRe: purpose of parameter value of -1 ? Pin
CPallini10-Feb-24 22:32
mveCPallini10-Feb-24 22:32 
GeneralRe: purpose of parameter value of -1 ? Pin
Richard MacCutchan11-Feb-24 2:19
mveRichard MacCutchan11-Feb-24 2:19 
GeneralRe: purpose of parameter value of -1 ? Pin
CPallini11-Feb-24 4:12
mveCPallini11-Feb-24 4:12 
QuestionUsing /bin/sh "partially " works Pin
Salvatore Terress9-Feb-24 6:10
Salvatore Terress9-Feb-24 6:10 
AnswerRe: Using /bin/sh "partially " works Pin
Mircea Neacsu9-Feb-24 6:47
Mircea Neacsu9-Feb-24 6:47 
AnswerRe: Using /bin/sh "partially " works Pin
k50549-Feb-24 6:59
mvek50549-Feb-24 6:59 
We keep telling you, QT is not within the scope of this forum. If you're going to continue posting questions, at least rephrase them as non QT C++

As such, you could rewrite your sudo problem as follows
C++
#include <cstdio>

int main()
{
    system("sudo ps");
}

Now, either you'll have sudo set up to allow you to run commands without a password, in which case you should get a process list back, or you will be prompted for a password. My guess is that sudo is trying to prompt for a password, but whatever QT is doing, you never see the password prompt. Or maybe if you look at an attached terminal or wherever stdout gets sent to, you'll find the password prompt there.

I'd suggest you compile this very simple program and try it from a command line. If it prompts for a password, then you know what the issue is. If it works, then you probably need to ask on a QT forum, as it would seem the issue is something that QT is doing. For all we know QT intercepts sudo requests and handles them differently.

Note that the parameter to the system call is just "sudo ps", you don't need to specify the shell to use, sudo will use some default shell, probably the shell named in /etc/passwd as the user's shell. But there may be a way to override that. I'm just feeling too lazy to dig into the sudo docs Smile | :)

Addionally, assuming you need the output from hci info, the system() call is not a good choice. To capture the output, you'd need to redirect stdout to a file, then read that file back in to examine the output. Much better would be to use popen(). Or since you're using QT, then maybe QProcess would be a better fit. There's a quick example of how to do this here : https://stackoverflow.com/a/19413789
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown

AnswerRe: Using /bin/sh "partially " works Pin
jschell9-Feb-24 12:29
jschell9-Feb-24 12:29 
QuestionConcurrent linked list Pin
cod3Ninj47-Feb-24 23:40
cod3Ninj47-Feb-24 23:40 
AnswerRe: Concurrent linked list Pin
jschell9-Feb-24 12:32
jschell9-Feb-24 12:32 
Questionget_string memory leak? Pin
mike74115-Feb-24 9:57
mike74115-Feb-24 9:57 
AnswerRe: get_string memory leak? Pin
Dave Kreskowiak5-Feb-24 10:03
mveDave Kreskowiak5-Feb-24 10:03 
GeneralRe: get_string memory leak? Pin
Mircea Neacsu5-Feb-24 14:13
Mircea Neacsu5-Feb-24 14:13 
GeneralRe: get_string memory leak? Pin
mike74115-Feb-24 20:05
mike74115-Feb-24 20:05 
GeneralRe: get_string memory leak? Pin
Mircea Neacsu5-Feb-24 20:22
Mircea Neacsu5-Feb-24 20:22 
GeneralRe: get_string memory leak? Pin
Dave Kreskowiak6-Feb-24 4:39
mveDave Kreskowiak6-Feb-24 4:39 
GeneralRe: get_string memory leak? Pin
Mircea Neacsu6-Feb-24 6:59
Mircea Neacsu6-Feb-24 6:59 
GeneralRe: get_string memory leak? Pin
Dave Kreskowiak6-Feb-24 12:22
mveDave Kreskowiak6-Feb-24 12:22 
GeneralRe: get_string memory leak? Pin
Mircea Neacsu6-Feb-24 12:28
Mircea Neacsu6-Feb-24 12:28 
AnswerRe: get_string memory leak? Pin
jschell6-Feb-24 5:02
jschell6-Feb-24 5:02 
GeneralRe: get_string memory leak? Pin
k50546-Feb-24 5:15
mvek50546-Feb-24 5:15 
GeneralRe: get_string memory leak? Pin
RedDk6-Feb-24 10:06
RedDk6-Feb-24 10:06 
GeneralRe: get_string memory leak? Pin
jschell7-Feb-24 5:22
jschell7-Feb-24 5:22 
GeneralRe: get_string memory leak? Pin
charlieg12-Feb-24 23:04
charlieg12-Feb-24 23:04 

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.