Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Remote command shell
I decided to create some sort of my own remote command shell. I have implemented it on QTcpSocket and QTcpServer.
Creation of client and server was the easiest part. But now I have problem with executing the command that I send from my clent to server. I know that QT does have QProcess class that executes what I send to it. I know how to get the output streams from part of programs that I run. In fact on this moment I have some tool (my program) that allows me to launch one command at a time. This is not the way the comman shell should work. When we use CMD in windows or Shell in Lunix we allways have an ability to launch a bunch of command, by giving the list of commands and waiting for the results.
I'd like to know if there is any way to connect to the CMD or Shell process that I will create, send commands to it and the most necessary, redirect all output data to my client?
P.S. I don't want to use batch or bash files. I'd like to use only Qt enviroment and Qt classes.
tucnak last edited by
bq. P.S. I don’t want to use batch or bash files. I’d like to use only Qt enviroment and Qt classes.
Why don't make temporary file in /tmp/qt/.... with .sh extension and run it with this code:
QProcess *proc = new QProcess(this);
proc.start("sh", QStringList() << fileFullPath);
I think it will be the best solution to execute a list of commands.
P.S. Use Qt instaed of QT (Quick Time), please. It has been written in rules that you see on the post page.
tucnak, main idea to eliminate the need for making some changes in source code when I compile it for different OS.
I thought about an ability to check the type of OS while program is running and depending on it's type use batch (for Windows) or bash (Linux) files. But I don't think that this is a good way to solve a problem. Maybe there're some other ways?
tucnak last edited by
As far as I unsrstood, you need #ifdef statements. They allow to check current OS and execute special code for it. So, learn about it.
Yep, also Qt has QSysInfo class that give me information about current OS.
I'm not shure about this way to sort it out.
twsimpson last edited by
Don't change your servers behaviour at run-time, the OS is something that does not change from run to run. You use use #ifdef's and the Qt Q_OS_* macros to determine what behaviour your server-side should use at compile time instead.