简体   繁体   中英

Passing password from GUI to CLI on Linux.

I have developed an application in Linux using C language which has command line interface. It is completely an independent application. Now I am making a GUI interface for it also in C using gtk library. In CLI, before a certain operation, my CLI application waits for a password (just like they do it in useradd command line utility in linux). For this purpose I will create a window with password field asking for password in GUI.

My question is that how will I transfer the password from GUI to the application that is waiting for password in CLI? Can I redirect the password taken from GUI to the stdin of CLI process?

Also please let me know if my approach is correct or what are the standard ways of doing it?

Any help would be appreciated.

Sure you can. I don't know much about GTK, but you can simply use popen , that is for sure. For bidirectional communication take a look at Can popen() make bidirectional pipes like pipe() + fork()?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM