PDA

View Full Version : QProcess / system call not working under linux. Why?



johnny_sparx
10th March 2006, 21:42
Hello, thanks to all that replied to my previous posts.

I wish to execute the following command (which works fine at the actual command line - tested under linux already):

dcmodify -m "(0010,0020)=123456789" /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*

I tried the following code:


QString Command_Line = QString("dcmodify -m")+QString("\"(")+Key_String_Value+QString(")=")+Data_Value+"\" ";
#ifdef Q_WS_WIN
Command_Line+=QString("\"")+Target_File_Path+QString("\\")+File_Name+QString("\"");
#else
Command_Line+=(Target_File_Path+"/"+File_Name);
#endif

System_Call.start(Command_Line);
System_Call.waitForFinished();


It seems to work just fine under windows.

nothing seems to happen. I do not even get anything when I try to dump the standard output. Can anyone tell me why?

jacek
10th March 2006, 22:08
QProcess will start your program directly --- not through shell. This means that wildcards won't be replaced by a list of paths (i.e. you are trying to run dcmodify on a file named "*.*").

yop
10th March 2006, 22:18
You could get the files in [...]/SEBASTIAN_HEAD_4/ and start a QProcess for each one of them when the previous one finishes.

jacek
10th March 2006, 22:27
You could get the files in [...]/SEBASTIAN_HEAD_4/ and start a QProcess for each one of them when the previous one finishes.
IMO it would be better to run that program on larger number of files (but not too large). One can easily create a list of files using QDir::entryList().

johnny_sparx
10th March 2006, 22:30
The wildcards are processed by dcmodify and work fine for the port of this command to windows.

I just tried this:



System_Call.start("dcmodify -m \"(0010,0020)=1234\" /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*");
System_Call.waitForFinished();
QByteArray X = System_Call.readAllStandardOutput();
std::cout <<*X.constData();


I did not see anything on stdout and the command did not work. I would have expected this to work.

jacek
10th March 2006, 22:50
Does it work when you replace "*.*" with a name of a particular file? Maybe your application can't find dcmodify executable?

Bojan
10th March 2006, 22:53
The wildcards are processed by dcmodify and work fine for the port of this command to windows.

This is usually the case for windows ports of unix command line applications. Under unix, it is the shell that actually expands the wildcards. However under windows the command prompt does no such thing, so in the port they will usually implement this in the app themselves. Hence your QProcess works ok on windows but not on unix environment. I am not sure if this is the problem in this situation, but I have come across windows ports that do this. For example even qembed does it.

Bojan

johnny_sparx
10th March 2006, 23:00
I just tried this:



System_Call.start("dcmodify -m \"(0010,0020)=1234\" /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/dicom-0000-muehlboeck_sebastien_20051126.085338_1_1.dcm");
System_Call.waitForFinished();
QByteArray X = System_Call.readAllStandardOutput();
std::cout <<*X.constData();



Nothing goes to the console. How can I tell that it was attempted to even try to execute?

jacek
10th March 2006, 23:06
Try:
System_Call.start("dcmodify -m ...");
if( System_Call.waitForStarted() == false ) {
std::cerr << "error" << std::endl;
}
else {
System_Call.waitForFinished();
QByteArray X = System_Call.readAllStandardOutput();
std::cerr << X.constData() << std::endl;
}

johnny_sparx
10th March 2006, 23:40
I tried it, but got nothing on the console....
I still seem to get no results when I try to hard code even a single file (known to exist)... I tried startDetached and this seems to give *something* on the console... so it is a good start. Oddly enough, under linux, this does work for another section of code:



QString AcquisitionBrowserWidget::Get_DICOM_Information(QS tring File_Name, QString Key_String_Value)
{
// Call 'dcmdump' from the DCMTK 3.5.4 toolkit (already in path), retrieve the result
// from 'stdout'. Do a search for the specified key using a regular expression.
QDir Directory(Target_File_Path);
QFileInfoList Files;
QProcess System_Call(this);

// Create the parameter list for the external call. Check operating system.
QStringList Parameters;
#ifdef Q_WS_WIN
Parameters<<("\""+Target_File_Path+"\\"+File_Name+"\"");
#else
Parameters<<(Target_File_Path+"/"+File_Name);
#endif

// Make the system call. Wait until execution is complete, then retrieve 'stdout' in a buffer.
System_Call.start("dcmdump",Parameters);
QString Standard_Output_Buffer;
System_Call.waitForFinished();
Standard_Output_Buffer = System_Call.readAllStandardOutput();

// Search the buffer for the key in the correct format. The key is assumed to be UNIQUE.
QString RegExp = "([(]"+Key_String_Value+"[)])( [A-Z]{2} )([[])([ \\w,.:-]*)([]])";
QRegExp Key_Pattern(RegExp);
if(Key_Pattern.indexIn(Standard_Output_Buffer,0)>-1)
{
// The key was found, return it from the fourth regular expression grouping.
//(*Output)<<Key_Pattern.cap(4)<<endl;
return Key_Pattern.cap(4);
}
else
{
// The key was not found.
//(*Output)<<RegExp<<endl; // Keep the fourth regular expression grouping.
return KEY_NOT_FOUND;
}
}

Is voodo at work here? This is curious, and given the timing of this problem and my work deadline on monday... I am suspecting that dark forces are at work. This problem is very odd.

jacek
10th March 2006, 23:43
Does "std::cerr << "something" << std::endl;" writes something on the console?

johnny_sparx
11th March 2006, 00:20
Yes it does.

For a single file, no wildcard, when I use start() I get the following output to the console (there are multiple calls to this section of code):


roetgen 102% something
QProcess object destroyed while process is still running.
something
QProcess object destroyed while process is still running.
something
QProcess object destroyed while process is still running.
something
QProcess object destroyed while process is still running.
something
QProcess object destroyed while process is still running.
something
QProcess object destroyed while process is still running.


With startDetached(), I get this:



roetgen 104% something
something
something
something

something


Tsomething


There were 0 error(s)


There were 0 error(s)
here were 0 error(s)

There were 0 error(s)




error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/dicom-0000-muehlboeck_sebastien_20051126.085338_1_1.dcm

There were 1 error(s)
There were 0 error(s)



A race condition is expected since repeated calls are happening on the same file.

I suspect that Bojan may be on to something with the wildcards. If I insert the wildcard back and repeat the same experiment above, I get first (start()):



roetgen 111% something
QProcess object destroyed while process is still running.
something
QProcess object destroyed while process is still running.
something
QProcess object destroyed while process is still running.
something
QProcess object destroyed while process is still running.
something
QProcess object destroyed while process is still running.
something
QProcess object destroyed while process is still running.





...and then for startDetached(), I get:



roetgen 108% something
something
something


error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*

There were 1 error(s)
something
something
something


error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*

There were 1 error(s)


error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*

There were 1 error(s)


error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*

There were 1 error(s)



error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*

There were 1 error(s)

error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*

There were 1 error(s)




The solution here has much to do with the way the operating systems deal with external processes and how they process wildcards as parameters. Does this sound reasonable?

JS

jacek
11th March 2006, 00:32
QProcess object destroyed while process is still running.
Maybe QProcess::waitForFinished() timeout is too small? What does QProcess::error() return?


The solution here has much to do with the way the operating systems deal with external processes and how they process wildcards as parameters. Does this sound reasonable?
Yes, under Unices wildcards won't be processed.