本文介绍了在Qt QProcess中运行sudo命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Qt中开发软件,并在其中创建了一个终端.我通过 QProcess 运行不同的命令,但是当我运行root命令时,它要求在终端输入密码.我试图通过 sudo 运行,但它仅在终端中接受密码.有什么方法可以从弹出窗口小部件或文本文件等其他来源提供密码?

I am developing a software in Qt in which I created a terminal. I run different commands through QProcess in that but when I run root commands it ask for password in terminal. I tried to run via sudo but it only accepts password in terminal. Is there any way to give password from another source like pop up widget or a text file?

推荐答案

我创建了一个以"bash"为程序的QProcess.

I have created a QProcess with "bash" as program.

然后只写它:

echo mypassword | sudo -S ifconfig eth0 192.168.1.123\n

这篇关于在Qt QProcess中运行sudo命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 07:14