Communicating with xterm
-
Hello all,
This is my firs post in this forum and also I am new to Qt.
I am developing an application in which i need to run certain commands on a emulated terminal.
I am started to use "XTERM". I am able to open xterm but not able to send commands to it.
Can any one please help me in this regard.@QString program = "xterm";
QProcess *proc = new QProcess;
proc->start(program);
proc->waitForStarted();
proc->write("ls\n");@i like to know weather is there any other terminal emulator to communicate efficiently.... ?
Thanks in advance
Murali krishna -
No, you can't communicate with xterm (send something to its standart input). But you can communicate that way with "/bin/sh", for example:
@
QProcess proc;
proc.start("/bin/sh");
proc.waitForStarted();
Q_FOREACH( QString cmd, QStringList() << "ls" << "date" << "echo test" )
{
proc.write((cmd + "\n").toLocal8Bit());
proc.waitForReadyRead();
qDebug() << proc.readAllStandardOutput().split('\n');
}
proc.write("exit\n");
proc.waitForFinished();
@
or if you want you can run those program directly:
@
QProcess proc;
proc.start("ls");
proc.waitForFinished();
qDebug() << proc.readAllStandardOutput();
@P.S.: examples from "stackoverflow":http://stackoverflow.com/questions/15050462/qprocess-call-write-function-failure, but i have tested it, it works. Hope this helps.
-
Hello Thanks for the post.
But my application need an emulated terminal to excute commands.Thanks and regards,
Murali krishna.