Hi,
I have a script that returns a number that is the percentage of partition used, it looks like
#!/bin/bash
case $1 in
root_partition)
devname="/dev/sda1"
let p=`df -k $devname | grep -v ^File | awk '{printf ("%i",$3*100 / $2); }'`
echo $p
;;
default)
echo "Unknown command"
;;
esac
exit 0
#!/bin/bash
case $1 in
root_partition)
devname="/dev/sda1"
let p=`df -k $devname | grep -v ^File | awk '{printf ("%i",$3*100 / $2); }'`
echo $p
;;
default)
echo "Unknown command"
;;
esac
exit 0
To copy to clipboard, switch view to plain text mode
I have a QProcess that looks like this
arguments.clear();
qDebug("proc running");
arguments << " root_partition ";
if (_proc
->state
() == QProcess::NotRunning) {
_proc->disconnect();
connect(_proc, SIGNAL(readyReadStandardOutput()), this, SLOT(outLog()));
_proc->start(program, arguments);
_proc
->setReadChannel
(QProcess::StandardOutput);
_proc->waitForFinished();
}
}
void MyClass::outLog()
{
qDebug("outLog");
QByteArray array
= _proc
->readAllStandardOutput
();
}
QStringList arguments;
QString program = "script.sh";
arguments.clear();
_proc = new QProcess(this);
qDebug("proc running");
arguments << " root_partition ";
if (_proc->state() == QProcess::NotRunning)
{
_proc->disconnect();
connect(_proc, SIGNAL(readyReadStandardOutput()), this, SLOT(outLog()));
_proc->start(program, arguments);
_proc->setReadChannel(QProcess::StandardOutput);
_proc->waitForFinished();
}
}
void MyClass::outLog()
{
qDebug("outLog");
QByteArray array = _proc->readAllStandardOutput();
}
To copy to clipboard, switch view to plain text mode
My problem is that running the script by hand returns 87 - the % used on that partition. But running the script in my QT code does not work. If I replace the line
QString program = "script.sh";
To copy to clipboard, switch view to plain text mode
with
QString program = "echo";
To copy to clipboard, switch view to plain text mode
I get "root partition" returned - as expected. But why cannot I not anything back from running the script in Qt? The outLog function never gets called? Is echo not standard output?
I have done quite a bit of Googling but other people working solutions are not working for me? 
Thank you very much for helping.
cheers,
Tara
Qt4 on Linux
Bookmarks