How to set ip address to a computer in Qt (Solved)
-
i vi a file in /home/ubuntu/passwd.txt with my password. Debug the code. After Application finished running, i do a ifconfig in ubuntu terminal. The ip address has not been changed
@
void SetpcAddress{QProcess *myProcess = new QProcess(); QStringList args; args<<"-c"<< "sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt"; myProcess->start("/bin/sh",args);
}
int main(void)
{SetpcAddress();
}
@
-
Does that command work from outside ?
-
Does that command work from outside ?
-
It does work for me from the App and Outside
@
args<<"-c"<<
"sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt";
@There should be a space before and after < in above command.
-
It does work for me from the App and Outside
@
args<<"-c"<<
"sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt";
@There should be a space before and after < in above command.
-
Well then get the errors using readyReadStandardError() signal if any.
-
Well then get the errors using readyReadStandardError() signal if any.
-
It is for sh so that it reads commands from argument strings. Check "this":http://manpages.ubuntu.com/manpages/utopic/en/man1/sh.1posix.html man page for more details. I hope your system has sh command.
-
It is for sh so that it reads commands from argument strings. Check "this":http://manpages.ubuntu.com/manpages/utopic/en/man1/sh.1posix.html man page for more details. I hope your system has sh command.
-
QProcess Class is used to start external programs and to communicate with them.
create a new QProcess and input args to /bin/sh.
Below code has been tested working.
Thanks to p3c0, if not, answer below will not be available :QProcess *myProcess = new QProcess; QStringList args; args<"-c"<<"sudo -S ifconfig eth0 192.168.100.1 < /var/passwd.txt"); myProcess->start("/bin/sh",args);