QProcess / system call not working under linux. Why?
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:
Code:
#ifdef Q_WS_WIN
#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?
Re: QProcess / system call not working under linux. Why?
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 "*.*").
Re: QProcess / system call not working under linux. Why?
You could get the files in [...]/SEBASTIAN_HEAD_4/ and start a QProcess for each one of them when the previous one finishes.
Re: QProcess / system call not working under linux. Why?
Quote:
Originally Posted by yop
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().
Re: QProcess / system call not working under linux. Why?
The wildcards are processed by dcmodify and work fine for the port of this command to windows.
I just tried this:
Code:
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.
Re: QProcess / system call not working under linux. Why?
Does it work when you replace "*.*" with a name of a particular file? Maybe your application can't find dcmodify executable?
Re: QProcess / system call not working under linux. Why?
Quote:
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
Re: QProcess / system call not working under linux. Why?
I just tried this:
Code:
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?
Re: QProcess / system call not working under linux. Why?
Try:
Code:
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;
}
Re: QProcess / system call not working under linux. Why?
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:
Code:
{
// 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;
// Create the parameter list for the external call. Check operating system.
#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);
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,.:-]*)([]])";
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.
Re: QProcess / system call not working under linux. Why?
Does "std::cerr << "something" << std::endl;" writes something on the console?
Re: QProcess / system call not working under linux. Why?
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):
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:
Code:
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()):
Code:
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:
Code:
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
Re: QProcess / system call not working under linux. Why?
Quote:
Originally Posted by johnny_sparx
QProcess object destroyed while process is still running.
Maybe QProcess::waitForFinished() timeout is too small? What does QProcess::error() return?
Quote:
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.