c - Trying to pass sudo password directly through STDIN -


this program, , doesn't seem working. thought worked \0 or \r instead of \n, guess because had executed sudo command on terminal ran program, didn't prompt me password.

#include<stdio.h> #include<string.h> #include<stdlib.h>  int main() {    file* pipe = popen("sudo -s ls", "w");       pwrite(pipe,"mypass\n");    pclose(pipe);    return 0; } 

where going wrong? how can fix it? thanks.

i found out workaround seems working. everyone, looked question.

#include<stdio.h> #include<string.h> #include<stdlib.h>  int main() {    file* pipe = popen("echo mypass | sudo -s ls", "w");       pclose(pipe);    return 0; } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -