[英]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.