Qt-interest Archive, December 2006
QProcess problem on Windows (Qt 4.2.2) - no output
Message 1 in thread
I am trying to launch a little command-line tool with a QProcess on
Windows, and read the standard output. Unfortunately, I get nothing at
all when the process is finished, even with the exact same command line
that works when typed into a shell. The command DOES produce some text
on standard output when run from the shell though.
Here is my code:
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.start(path_to_cmd, QProcess::ReadOnly);
if (process.waitForFinished())
{
QByteArray result = process.readAll();
// result is always empty
}
--
[ signature omitted ]
Message 2 in thread
On 12.12.06 16:42:14, Paul Miller wrote:
> I am trying to launch a little command-line tool with a QProcess on Windows,
> and read the standard output. Unfortunately, I get nothing at all when the
> process is finished, even with the exact same command line that works when
> typed into a shell. The command DOES produce some text on standard output when
> run from the shell though.
>
> Here is my code:
>
> QProcess process;
> process.setProcessChannelMode(QProcess::MergedChannels);
> process.start(path_to_cmd, QProcess::ReadOnly);
>
> if (process.waitForFinished())
> {
> QByteArray result = process.readAll();
> // result is always empty
> }
Are there maybe environment variables involved when the program is run
from a shell? Or a special working directory? Did you try another
program?
Did you check that isRunning() and the exitStatus/exitCode functions
return proper Status/Code?
Just guessing here...
Andreas
--
[ signature omitted ]
Message 3 in thread
Andreas Pakulat wrote:
> On 12.12.06 16:42:14, Paul Miller wrote:
>> I am trying to launch a little command-line tool with a QProcess on Windows,
>> and read the standard output. Unfortunately, I get nothing at all when the
>> process is finished, even with the exact same command line that works when
>> typed into a shell. The command DOES produce some text on standard output when
>> run from the shell though.
>>
>> Here is my code:
>>
>> QProcess process;
>> process.setProcessChannelMode(QProcess::MergedChannels);
>> process.start(path_to_cmd, QProcess::ReadOnly);
>>
>> if (process.waitForFinished())
>> {
>> QByteArray result = process.readAll();
>> // result is always empty
>> }
>
> Are there maybe environment variables involved when the program is run
> from a shell? Or a special working directory? Did you try another
> program?
This is the second time I've tried to use QProcess with very simple
command line programs, both of which only spit some results to standard
output, and neither has worked.
> Did you check that isRunning() and the exitStatus/exitCode functions
> return proper Status/Code?
Yep - everything appeared to be correct, except no output.
The odd thing here is that one of the arguments to the command is the
path to an image file. After QProcess finished, Photoshop launches and
loads the image. It's like QProcess is passing the last argument on to
the UI shell and it is acting like I tried to launch the file.
--
[ signature omitted ]
Message 4 in thread
On 13.12.06 10:25:25, Paul Miller wrote:
> The odd thing here is that one of the arguments to the command is the path to
> an image file. After QProcess finished, Photoshop launches and loads the image.
> It's like QProcess is passing the last argument on to the UI shell and it is
> acting like I tried to launch the file.
Aaah, then you're using QProcess the wrong way ;) If you want to give
arguments to your program use the 2nd for of start, taking a QString for
the binary and a QStringList of the arguments. For example
QProcess proc;
proc.start( "copy", QStringList() << "/?", QProcess::Merged)
Andreas
--
[ signature omitted ]
Message 5 in thread
Andreas Pakulat wrote:
> On 13.12.06 10:25:25, Paul Miller wrote:
>> The odd thing here is that one of the arguments to the command is the path to
>> an image file. After QProcess finished, Photoshop launches and loads the image.
>> It's like QProcess is passing the last argument on to the UI shell and it is
>> acting like I tried to launch the file.
>
> Aaah, then you're using QProcess the wrong way ;) If you want to give
> arguments to your program use the 2nd for of start, taking a QString for
> the binary and a QStringList of the arguments. For example
>
> QProcess proc;
> proc.start( "copy", QStringList() << "/?", QProcess::Merged)
No, I was doing that properly. The problem ended being that the binary I
was trying to run was a 16 bit console program for some reason.
--
[ signature omitted ]
Message 6 in thread
Paul Miller wrote:
> Andreas Pakulat wrote:
>> On 12.12.06 16:42:14, Paul Miller wrote:
>>> I am trying to launch a little command-line tool with a QProcess on
>>> Windows, and read the standard output. Unfortunately, I get nothing
>>> at all when the process is finished, even with the exact same command
>>> line that works when typed into a shell. The command DOES produce
>>> some text on standard output when run from the shell though.
>>>
>>> Here is my code:
>>>
>>> QProcess process;
>>> process.setProcessChannelMode(QProcess::MergedChannels);
>>> process.start(path_to_cmd, QProcess::ReadOnly);
>>>
>>> if (process.waitForFinished())
>>> {
>>> QByteArray result = process.readAll();
>>> // result is always empty
>>> }
>>
>> Are there maybe environment variables involved when the program is run
>> from a shell? Or a special working directory? Did you try another
>> program?
>
> This is the second time I've tried to use QProcess with very simple
> command line programs, both of which only spit some results to standard
> output, and neither has worked.
>
>> Did you check that isRunning() and the exitStatus/exitCode functions
>> return proper Status/Code?
>
> Yep - everything appeared to be correct, except no output.
>
> The odd thing here is that one of the arguments to the command is the
> path to an image file. After QProcess finished, Photoshop launches and
> loads the image. It's like QProcess is passing the last argument on to
> the UI shell and it is acting like I tried to launch the file.
I found the problem. The program I was trying to run was a 16 bit
console application. I got the sourcecode to it and recompiled as a 32
bit console app and it now works as expected.
--
[ signature omitted ]