PDA

View Full Version : "Process failed to start: " and qprocess generic errors



scott_hollen
19th November 2011, 21:11
Afternoon --

I can't seem to find a simple problem I'm having addressed anywhere in the forum or google, so I'm hoping someone can point me in the right direction...I'm sure it's something small...

I am trying to call a simple cmd application that takes 2 parameters, an input file and output file with QProcess -- it looks like it should be a very easy thing to do but I'm getting errors that really don't help me much...if I use "proc->start(...)" the error I get is, "Process failed to start: ", and if I use proc->execute (...), I get "Unknown error"...It might be something in my pathnames, but I need another set of eyes at this point...

From the command line, this is how I call the application and it works perfectly:
C:\Users\Scott\Desktop\Star\Genriser\src\genriser test.input test.output

mainwindow.h


.
.
.
private:
Ui::MainWindow *ui;
QProcess *genriser_proc;


mainwindow.cpp


QString genriser_dir;
QStringList arguments;

genriser_proc = new QProcess;

genriser_dir = "C:\\Users\\Scott\\Desktop\\Star\\Genriser\\src";
QDir::setCurrent(genriser_dir);

arguments << "test.input";
arguments << "test.output";

genriser_proc->start(program, arguments);


I have tried not setting a working directory and putting the full pathname of the executable and the files in the string, I've tried the overloaded versions of QProcess::start and execute, but to no avail.


Any ideas? I'm sure it'll be something embarrassing...

scott

norobro
19th November 2011, 22:18
Have you tried:
genriser_dir = "C:\\Users\\Scott\\Desktop\\Star\\Genriser\\src";
//QDir::setCurrent(genriser_dir);
genriser_proc->setWorkingDirectory(genriser_dir);

scott_hollen
19th November 2011, 22:44
That's actually what I tried first but was getting a can't find directory or file error, so searching found me this:

http://www.qtforum.org/article/15350/qprocess-setworkingdirectory-problem.html

ChrisW67
21st November 2011, 01:34
Where is 'program' set and what is its value?

scott_hollen
21st November 2011, 13:56
Oops, that would help to have shown the whole piece of code -- cut and paste issues...

mainwindow.cpp

QString input_file;
QString output_file;
QString program;
QString genriser_dir;
QStringList arguments;

input_file = "C:\\Users\\Scott\\Desktop\\Starmark\\Genriser\\src \\test.input";
output_file = "C:\\Users\\Scott\\Desktop\\Starmark\\Genriser\\src \\test.output";
program = "C:\\Users\\Scott\\Desktop\\Starmark\\Genriser\\src \\genriser";
genriser_dir = "C:\\Users\\Scott\\Desktop\\Starmark\\Genriser\\src";

genriser_proc = new QProcess;

QDir::setCurrent(genriser_dir);

arguments << input_file;
arguments << output_output;

genriser_proc->start(program, arguments);


If I fully qualify the pathnames in my variables, I get the "Process failed to start" error...However, if I remove the pathnames and just rely on the setCurrent command to define the directory, I get "Process crashed"...

When I did a qDebug() on "arguments", it shows the string encased in parentheses, and I'm wondering if that's where my problem is originating because my command line needs to look like this, "...\src\genriser test.input test.output"...Does the QStringlist append parenthesis or is that something that's just appearing with the debug?

I've also tried, "genriser_proc->start("genriser test.input test.output)" and that didn't work either...


scott


ed. calling my main application, which has no parameters, works -- so does run qtcreator if I point all my variables to it's directory, so that narrows it down to something to do with the arguments...

scott_hollen
22nd November 2011, 01:12
I'm about to throw my Mac against the wall...Every application I invoke with QProcess works except for the one I need to have work...I even modified the external app to not need parameters but it still bombs...Running that app from the cmd line works; double clicking on it in File Manager works...Calling it from my Qt app generates a "Process crashed" error and I'm at a loss as to how to debug that...I didn't want to have to fold this app into my Qt app, but I'm almost to the point of having to do that...

scott

ChrisW67
22nd November 2011, 01:18
If it is complaining that the process crashed then it must have found the file.

Are you sure the genriser program runs on its own without crashing?
Can you start a non-Qt command prompt (whatever it's called on a Mac), cd to the directory, and run the command yourself?
Is the environment that your sub-process inherits correct? Can the program find all its dynamically loaded dependencies (Qt libs etc.)?

When you say a "simple cmd application" do mean a simple executable or a shell script?

scott_hollen
22nd November 2011, 03:23
I'm running VMware on my Mac and it's running Vista...Also trying this on my Windows 7 machine with the same result...

Yep, 100% sure that genriser (genriser.exe) is working -- it takes an input file, does a lot of hocus pocus on it, and creates an output file which is then fed to another application...I can run it from the dos command prompt and it creates my output file, and I can double click on it in Windows Explorer as well and it creates the file...

The genriser app is a fairly large c++ application, compiles fine, executes fine...I've checked file perms, everything's fine...It resides in the exact same directory as my Qt application which is calling it (I've moved it all over the place thinking that might help but nooooooooo)...I can call other .exe apps with QProcess with no problem including my Qt application, qtcreator.exe itself and other Windows .exe's like calc and it works fine, so obviously I've narrowed it down to *something* with genriser, but I'm hitting a wall with the debugging of this; "process crashed" isn't exactly a detailed explanation...

Added after 1 23 minutes:

Well, when I run genriser thru QtCreator's external debugger, it works just fine so there must just be some working/running directory confusion going on when I kick it off from my Qt app...For testing reasons I've hardcoded genriser with files names without the path and since it works at the cmd prompt, Windows Explorer and now the debugger, that pretty much narrows it down to pathnames being off but how I don't know...Everything in my Qt app is hardcoded, I'm now setting a working directory and current directory to the same location as genriser, I've output the directory contents via Qt and still I'm crashing...

Time for a beer...Thanks for the help!!!

scott

scott_hollen
22nd November 2011, 15:03
SOLVED!!!! There was a compiler incompatibility issue apparently...I had been compiling my genriser app at the cmd line, so I created a new project in QtCreator and imported all the code and builtit there...Now my Qt app can call the newly Qt-generated genriser executable via QProcess!

Thanks for the help!


scott