[英]How to execute shell commands and interact with the output on linux using C++?
我使用Eclipse,並嘗試執行用cpp文件編寫的shell commands
。
據我所知,我可以使用system()
函數在cpp中執行shell command
,但是如何響應終端中的提示?
我知道在執行某些命令后,shell會要求輸入密碼,因此我必須將其放入其中。 最初,我嘗試將密碼放入第二個system()
函數,但此方法無效。 盡管我在兩個system()
函數調用之間都添加了sleep
調用,但它不起作用:
system(DO)// after this command the shell asks for a password
sleep(10)
system(Password)`
如何輸入密碼?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.