Results 1 to 13 of 13

Thread: QProcess / system call not working under linux. Why?

  1. #1
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:
    Qt Code:
    1. QString Command_Line = QString("dcmodify -m")+QString("\"(")+Key_String_Value+QString(")=")+Data_Value+"\" ";
    2. #ifdef Q_WS_WIN
    3. Command_Line+=QString("\"")+Target_File_Path+QString("\\")+File_Name+QString("\"");
    4. #else
    5. Command_Line+=(Target_File_Path+"/"+File_Name);
    6. #endif
    7.  
    8. System_Call.start(Command_Line);
    9. System_Call.waitForFinished();
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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 "*.*").

  3. #3
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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().

  5. #5
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. System_Call.start("dcmodify -m \"(0010,0020)=1234\" /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*");
    2. System_Call.waitForFinished();
    3. QByteArray X = System_Call.readAllStandardOutput();
    4. std::cout <<*X.constData();
    To copy to clipboard, switch view to plain text mode 

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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  7. #7
    Join Date
    Jan 2006
    Location
    N.B. Canada
    Posts
    47
    Thanked 8 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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.
    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
    Last edited by Bojan; 10th March 2006 at 22:57.
    The march of progress:
    C:
    printf("%10.2f", x);
    C++:
    cout << setw(10) << setprecision(2) << showpoint << x;
    Java:
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);

  8. #8
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess / system call not working under linux. Why?

    I just tried this:

    Qt Code:
    1. 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");
    2. System_Call.waitForFinished();
    3. QByteArray X = System_Call.readAllStandardOutput();
    4. std::cout <<*X.constData();
    To copy to clipboard, switch view to plain text mode 


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

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess / system call not working under linux. Why?

    Try:
    Qt Code:
    1. System_Call.start("dcmodify -m ...");
    2. if( System_Call.waitForStarted() == false ) {
    3. std::cerr << "error" << std::endl;
    4. }
    5. else {
    6. System_Call.waitForFinished();
    7. QByteArray X = System_Call.readAllStandardOutput();
    8. std::cerr << X.constData() << std::endl;
    9. }
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:

    Qt Code:
    1. QString AcquisitionBrowserWidget::Get_DICOM_Information(QString File_Name, QString Key_String_Value)
    2. {
    3. // Call 'dcmdump' from the DCMTK 3.5.4 toolkit (already in path), retrieve the result
    4. // from 'stdout'. Do a search for the specified key using a regular expression.
    5. QDir Directory(Target_File_Path);
    6. QFileInfoList Files;
    7. QProcess System_Call(this);
    8.  
    9. // Create the parameter list for the external call. Check operating system.
    10. QStringList Parameters;
    11. #ifdef Q_WS_WIN
    12. Parameters<<("\""+Target_File_Path+"\\"+File_Name+"\"");
    13. #else
    14. Parameters<<(Target_File_Path+"/"+File_Name);
    15. #endif
    16.  
    17. // Make the system call. Wait until execution is complete, then retrieve 'stdout' in a buffer.
    18. System_Call.start("dcmdump",Parameters);
    19. QString Standard_Output_Buffer;
    20. System_Call.waitForFinished();
    21. Standard_Output_Buffer = System_Call.readAllStandardOutput();
    22.  
    23. // Search the buffer for the key in the correct format. The key is assumed to be UNIQUE.
    24. QString RegExp = "([(]"+Key_String_Value+"[)])( [A-Z]{2} )([[])([ \\w,.:-]*)([]])";
    25. QRegExp Key_Pattern(RegExp);
    26. if(Key_Pattern.indexIn(Standard_Output_Buffer,0)>-1)
    27. {
    28. // The key was found, return it from the fourth regular expression grouping.
    29. //(*Output)<<Key_Pattern.cap(4)<<endl;
    30. return Key_Pattern.cap(4);
    31. }
    32. else
    33. {
    34. // The key was not found.
    35. //(*Output)<<RegExp<<endl; // Keep the fourth regular expression grouping.
    36. return KEY_NOT_FOUND;
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 

    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.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess / system call not working under linux. Why?

    Does "std::cerr << "something" << std::endl;" writes something on the console?

  12. #12
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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):

    Qt Code:
    1. roetgen 102% something
    2. QProcess object destroyed while process is still running.
    3. something
    4. QProcess object destroyed while process is still running.
    5. something
    6. QProcess object destroyed while process is still running.
    7. something
    8. QProcess object destroyed while process is still running.
    9. something
    10. QProcess object destroyed while process is still running.
    11. something
    12. QProcess object destroyed while process is still running.
    To copy to clipboard, switch view to plain text mode 

    With startDetached(), I get this:

    Qt Code:
    1. roetgen 104% something
    2. something
    3. something
    4. something
    5.  
    6. something
    7.  
    8.  
    9. Tsomething
    10.  
    11.  
    12. There were 0 error(s)
    13.  
    14.  
    15. There were 0 error(s)
    16. here were 0 error(s)
    17.  
    18. There were 0 error(s)
    19.  
    20.  
    21.  
    22.  
    23. error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/dicom-0000-muehlboeck_sebastien_20051126.085338_1_1.dcm
    24.  
    25. There were 1 error(s)
    26. There were 0 error(s)
    To copy to clipboard, switch view to plain text mode 

    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()):

    Qt Code:
    1. roetgen 111% something
    2. QProcess object destroyed while process is still running.
    3. something
    4. QProcess object destroyed while process is still running.
    5. something
    6. QProcess object destroyed while process is still running.
    7. something
    8. QProcess object destroyed while process is still running.
    9. something
    10. QProcess object destroyed while process is still running.
    11. something
    12. QProcess object destroyed while process is still running.
    To copy to clipboard, switch view to plain text mode 




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

    Qt Code:
    1. roetgen 108% something
    2. something
    3. something
    4.  
    5.  
    6. error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*
    7.  
    8. There were 1 error(s)
    9. something
    10. something
    11. something
    12.  
    13.  
    14. error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*
    15.  
    16. There were 1 error(s)
    17.  
    18.  
    19. error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*
    20.  
    21. There were 1 error(s)
    22.  
    23.  
    24. error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*
    25.  
    26. There were 1 error(s)
    27.  
    28.  
    29.  
    30. error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*
    31.  
    32. There were 1 error(s)
    33.  
    34. error: unable to load file /export/data/jsalik/DICOM_DB/PENDING/SEBASTIAN_HEAD_4/*.*
    35.  
    36. There were 1 error(s)
    To copy to clipboard, switch view to plain text mode 


    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

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

    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.

  14. The following 2 users say thank you to jacek for this useful post:

    johnny_sparx (13th March 2006), ucntcme (14th March 2006)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.