Hi,
why this code doesn't work ???
Code:
QStringList arguments; arguments << "-c" << "who|cut -d' ' -f1|sort -u"; QProcess *exec; exec->start("/bin/sh", arguments); ui->label->setText(exec->readLine(10));
Printable View
Hi,
why this code doesn't work ???
Code:
QStringList arguments; arguments << "-c" << "who|cut -d' ' -f1|sort -u"; QProcess *exec; exec->start("/bin/sh", arguments); ui->label->setText(exec->readLine(10));
QProcess works asynchronously. Please read QProcess docs. You might be interested in "Synchronous Process API".
ok i do ... but the real problem it is ...
for Run matlab in batch mode the command in the shell is
Code:
matlab -nojvm -nosplash -r MyCommand
where MyCommand is the name of m file ...
first question :
how to call this in my Qt app...???
if i do
don't workCode:
arguments << "matlab -nojvm -nosplash -nodisplay -r addmatrix"; exec->start("/bin/bash", arguments);
and second question :
if i open the terminal can i send the comand from my qt app???
sorry for the trouble and thanks in advance
These look like individual command line arguments to me.
Here you are not doing anything that would have to be interpret by a shell like you did in the first post.Quote:
Code:
arguments << "matlab -nojvm -nosplash -nodisplay -r addmatrix"; exec->start("/bin/bash", arguments);
Sorry, I don't understand. What do you mean?Quote:
if i open the terminal can i send the comand from my qt app???
before I have used
and this worksCode:
while(exec->waitForReadyRead()) ui->label->setText(exec->readLine(10));
What can i do ??Quote:
Here you are not doing anything that would have to be interpret by a shell like you did in the first post.
I manually launch shell and manually the start matlab in bash mode.Quote:
Sorry, I don't understand. What do you mean?
after start my Qt program and redirect the standartd input on the standard input of the shell as if the program wrote in shell to the place mine....CAN I DO THIS ???
I think this:
should look:Code:
matlab -nojvm -nosplash -r MyCommand
Code:
arguments << "-nojvm" << "-nosplash" << "-nodisplay" << "-r" << "addmatrix"; exec->start("matlab", arguments);
As I understand, you want to pass the input from you Qt app to the matlab?Quote:
I manually launch shell and manually the start matlab in bash mode.
after start my Qt program and redirect the standartd input on the standard input of the shell as if the program wrote in shell to the place mine....CAN I DO THIS ???
I would try starting matlab with a QProcess, and then writing and reading it's input/output, like sample code in assistant:
Code:
QProcess gzip; if (!gzip.waitForStarted()) return false; gzip.write("Qt rocks!"); gzip.closeWriteChannel(); if (!gzip.waitForFinished()) return false;
thanks for help ... it work... the right code is:
Code:
QStringList argo, list; QProcess *exec; argo <<"/Applications/MATLAB_R2008a/bin/matlab"<<"-nojvm -nosplash -nodisplay -r 'addmatrix(2,7)'"; list <<"PATH=/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/X11R6/bin"; exec->setEnvironment(list); exec->start("/bin/bash", argo);
if there are a different mode more easy please write :)