Results 1 to 10 of 10

Thread: Very simple output task

  1. #1
    Join Date
    Apr 2014
    Location
    Switzerland
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Post Very simple output task

    Hi everyone,

    I`m using QT 4.8 on a ubuntu 12.04 machine.

    I`m at the end of finishing a little software. But now I cant get through a very simple task. I`m a newbie but I try hard

    I just want to following linux command to be executed:

    rhash -rH --sha1 --md5 /hashfolder >hashlist

    Getting the output from rhash into the hashlist file.

    Qt Code:
    1. QProcess rhasher;
    2.  
    3. QString rhash = "rhash";
    4.  
    5. rhasher.startDetached(QString("rhash -rH --sha1 --md5 /hashfolder/));
    6.  
    7. QString results = rhasher.readAllStandardOutput();
    8.  
    9. QFile file("/home/user/hashliste");
    10.  
    11. file.open(QIODevice::WriteOnly | QIODevice::Text);
    12.  
    13. QTextStream out(&file);
    14.  
    15. out << results;
    16.  
    17. std::cout << "make MD5 und SHA1 hashes" << std::endl;
    18.  
    19. file.close();
    20.  
    21. rhasher.waitForFinished(-1);
    To copy to clipboard, switch view to plain text mode 

    I`m confusing myself right now. Hope you can help me out. Thanks


    greetings Nand
    Last edited by anda_skoa; 8th April 2014 at 17:36. Reason: missing [code] tags

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Very simple output task

    startDetached is a static method, use QProcess::start() and connect to QProcess::readyReadStandardOutput signal to be notified when your process writes to stdout.

  3. The following user says thank you to stampede for this useful post:

    nand (8th April 2014)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Very simple output task

    And allocate the process object on the heap.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    nand (8th April 2014)

  6. #4
    Join Date
    Apr 2014
    Location
    Switzerland
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Very simple output task

    ok thank you.

    I try the best I can, dont know if I can do this.

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Very simple output task

    Alternatively just use system() or popen() calls which are both blocking.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #6
    Join Date
    Apr 2014
    Location
    Switzerland
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Very simple output task

    thanks for youre help. But I`m a bloody newbie. I dont know how to do this.

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Very simple output task

    Open a terminal and type in "man popen" or search the internet.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #8
    Join Date
    Apr 2014
    Location
    Switzerland
    Posts
    4
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Very simple output task

    Qt Code:
    1. FILE *fp;
    2. int status;
    3. char path[PATH_MAX];
    4.  
    5.  
    6. fp = popen("rhash -rH --sha1 --md5 /home/user/ >hashlist", "r");
    7. if (fp == NULL)
    8. /* Handle error */;
    9.  
    10.  
    11. while (fgets(path, PATH_MAX, fp) != NULL)
    12. printf("%s", path);
    13.  
    14.  
    15. status = pclose(fp);
    16. if (status == -1) {
    17.  
    18.  
    19. } else {
    20.  
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 
    Maybe in a few days I`ve got it....
    Last edited by anda_skoa; 8th April 2014 at 17:37. Reason: missing [code] tags

  11. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Very simple output task

    I would always use QProcess over low level C API.

    If you really need it to be blocking use waitForFinished()

    Cheers,
    _

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Very simple output task

    You are redirecting the output to a file so I don't know what you are expecting to receive on stdout of the process.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 25th September 2013, 20:47
  2. Replies: 1
    Last Post: 20th July 2012, 11:46
  3. Replies: 3
    Last Post: 27th August 2011, 21:44
  4. Task Window in Qt
    By doberkofler in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2009, 08:00
  5. Task to another application
    By zlosynus in forum Qt Programming
    Replies: 0
    Last Post: 6th August 2008, 10:04

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.