Remote command shell
-
wrote on 27 Aug 2012, 17:57 last edited by
Hi
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.
-
wrote on 28 Aug 2012, 10:32 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);
//.... code
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.
-
wrote on 28 Aug 2012, 10:56 last edited by
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? -
wrote on 28 Aug 2012, 11:37 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.
-
wrote on 28 Aug 2012, 11:41 last edited by
Yep, also Qt has QSysInfo class that give me information about current OS.
I'm not shure about this way to sort it out. -
wrote on 28 Aug 2012, 11:48 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.
4/6