Solved Send arguments to LinuX Terminal with QProcess
-
@Alexanov You will not find it in the QProcess documentation because it is completely unrelated to QProcess. Those are parameters for commands which you want to execute. So, if you want to execute sh you need to read sh documentation. If you want to execute konsole then read its documentation. QProcess just starts an executable in a process and passes the parameter you provide, it does not care what executable is started and which parameters it supports.
-
@jsulm Thanks , I will read konsole documentation ...
My problem solved but i have little question that remained , if i want to send multiple executable commands and then see outputs ... how can i do that?(sequentially send and read output and go to next command ) -
@Alexanov You can write to the process using QProcess. There is an example here http://doc.qt.io/qt-5/qprocess.html
-
@Alexanov Hi Alexanov , are you able to sequentially send and read output ?? if yes, please attach a code snippet .
i tied this ,using write command but after one write command i had to use "closewriteterminal()" command in order to read standardoutput or standarderror. And next time , i cant send the write command since write terminal is closed. So i have to again use the start command to start my process. following is code snippet:QProcess myprocess ;
myprocess.start("python");
myprocess.write("print("hello")");
myprocess.waitForFinished();
myprocess.closeWriteChannel();
while(myprocess.waitForFinished())
{
qDebug()<<myprocess.readAll();
}// again i have to start the process
myprocess.start("python");//and then the next write command
myprocess.write("print("world")");can anybody tell better method to do it using Qprocess or any other . All solutions are welcom :)
-
Hi and welcome to the forums.
You start python in interactive mode so process never terminates.
maybe you can make it quit with
myprocess.write("exit()"); -
@mrjj Thanks for your suggestios. My worry is not about how to close python session. But how to send 2 write commands without starting again the python. Which means that one time only i will open the qPROCESS as python and then sequentially i write some command to python and read the output of python.
-
@Rajesh-Bhau
Ok so you want it to be interactive ?
see
https://forum.qt.io/topic/90904/how-do-i-run-docker-using-qprocess/8
i start python there and its interactive.
But its only for windows. -
@mrjj Thanks for the answer, i want to make Qtextedit to mimic like python console. So i am trying to open python as qprocess in background and then input from Qtextedit will got to Python.exe to process and based on that the standard output will get printed back to Qtextedit.
i tried using Qprocess its working fine except that i cant do sequential input\output as i told i have to close the write terminal and start it again. -
@Rajesh-Bhau
Yeah and for that to work, at least on windows, the process must be interactive for that to work.
it will just run command and exit. ( i think)
Looking at your code it seems to do that. so after print, it does terminate ? -
@Rajesh-Bhau
Oh maybe -i will help
python -i foo.py
do not quit
https://www.johnny-lin.com/cdat_tips/tips_pylang/keep_open.html
forget about the interactive shell. you dont want to type so that should not be needed.