简体   繁体   中英

how to avoid printing 'echo' output with system command in C

system("echo 'abcpasswd' | su - NewUsr -c 'ls -ltr'");

Above code embedded in my 'C' code which generats a binary , which is later called from a html page. Now the above code prompts for a 'Password' which is piped in the command. But i end up seeing the prompt 'Password:' in my html rendered page.

How do i get around this ?. I don't want the prompt 'Password:' seen on my webpage.

For security reasons, su doesn't takes password everywhere else than from an interactive terminal. Option - is just for full login not for standard input reading.

You may use sudo which you can control better (read your OS manual about it), beware using such in non interactive mode is considered as harmful...

Thanks everyone for your suggestions and comments. I found a way around this by handling it in the html/php side. By replacing 'passthru' by 'exec' and selectively picking what needs to be output to the page.

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