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
Post a Comment