Results 1 to 14 of 14

Thread: How to extract and compress a cpio archive file in Qt

  1. #1
    Join Date
    May 2006
    Posts
    32
    Thanks
    1
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How to extract and compress a cpio archive file in Qt

    Hello Everyone!

    I have a cpio archive file and want to extract the same and compress later after modifications are done to the archive file.

    I tried doing this using QProcess from Qt 4.

    Please anyone can guide me to do this.

    Thanks and Regards,
    Sarode
    Regards

  2. #2
    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: How to extract and compress a cpio archive file in Qt

    Your approach was correct. What went wrong?

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

    sarode (29th December 2007)

  4. #3
    Join Date
    May 2006
    Posts
    32
    Thanks
    1
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extract and compress a cpio archive file in Qt

    Hi,

    I tried by passing the arguments to QProcess::start(...) function with arguments
    command name as cpio and arguments as the file name but the process was not able to produce the output. Even when i checked the standard output for the output the data was not available.

    Do we need to set any mode before calling this function to copy all the data which is extracted from the archive file?

    Please clarify.

    Regards,
    Sarode
    Regards

  5. #4
    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: How to extract and compress a cpio archive file in Qt

    Maybe the process didn't start successfully?
    Either use waitForStarted() or check the state of the process after a while. Also make sure the executable is in the PATH and that you provided correct arguments for the process - i.e. remember that you shouldn't surround arguments with quotes or use any wildcards.

  6. #5
    Join Date
    May 2006
    Posts
    32
    Thanks
    1
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extract and compress a cpio archive file in Qt

    Hello,

    I tried to call the process cpio in the following way and used the conditions like waitForFinished() and waitForStated() - none of them gave me any indications. I think i am not using these flags properly.

    I have sent a piece of code below which i have written. Please clarify where went wrong.

    Qt Code:
    1. QProcess proc1;
    2. .....
    3.  
    4. void RunProcess::runProcess()
    5. {
    6. QString program = "/usr/bin/cpio";
    7. QStringList arguments;
    8. arguments << "-i < " << "archive file path";
    9.  
    10. proc1->start(program, arguments);
    11. if(proc1->waitForFinished())
    12. return;
    13. }
    To copy to clipboard, switch view to plain text mode 

    If i dont include the waitForFinished() flag the program says that the process is destroyed when the application is closed.

    Thanks and Regards,
    Wish you Happy new year
    Sarode
    Regards

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to extract and compress a cpio archive file in Qt

    Try
    Qt Code:
    1. arguments << "-i" << "<" << "archive file path";
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  8. #7
    Join Date
    May 2006
    Posts
    32
    Thanks
    1
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extract and compress a cpio archive file in Qt

    Hello,

    Tried passing the arguments as you suggest.

    Qt Code:
    1. QString program1 = "/usr/bin/cpio";
    2. QStringList arguments1;
    3. arguments1 << "-i" << "<" << "/tmp/rootfs/archivefile";
    4.  
    5. proc1->start(program1, arguments1);
    6. if(proc1->waitForStarted())
    7. qWarning("Not Started");
    To copy to clipboard, switch view to plain text mode 

    But still not able to execute the process. Here even the if condition will not be true.

    Please clarify

    Regards,
    Sarode
    Regards

  9. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to extract and compress a cpio archive file in Qt

    Try what's being suggested in this post.
    J-P Nurmi

  10. #9
    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: How to extract and compress a cpio archive file in Qt

    "<" is a shell redirect command, isn't it? It won't work here as there is no shell. You need to perform the redirection yourself by writing to stdin of the process.

  11. #10
    Join Date
    May 2006
    Posts
    32
    Thanks
    1
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extract and compress a cpio archive file in Qt

    Hi,

    Tried the other option specified the following output.

    Qt Code:
    1. QStringList arguments1;
    2. arguments1 << "-i" << "<filename_with_absolute_path";
    3. // other option
    4. // arguments1 << "-i" << "<" << "filename_with_absolute_path";
    5.  
    6. proc1->start("/usr/bin/cpio", arguments1);
    7.  
    8. if(!proc1->waitForFinished())
    9. qWarning("Returned");
    10.  
    11. connect(proc1, SIGNAL(started()), this, SLOT(readData()));
    12.  
    13. void Process::readData()
    14. {
    15. qWarning("Started");
    16. }
    To copy to clipboard, switch view to plain text mode 

    I got the following output. the process is able to start when i checked for the pid of the process, the state of the process is also S+ in #pa ax

    The program halts with following output
    Returned
    QProcess: Destroyed while process is still running.

    I am not able to understand, can we read the output generated by any buffer?

    Regards,
    Sarode
    Regards

  12. #11
    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: How to extract and compress a cpio archive file in Qt

    You still use a redirection! You can't do that as there is no shell running over QProcess unless you start one yourself. Your "<" gets sent to cpio instead of the file contents it expects. The process starts but does nothing useful as it gets wrong data.

  13. #12
    Join Date
    Jan 2006
    Location
    Socorro, NM, USA
    Posts
    29
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Angry Re: How to extract and compress a cpio archive file in Qt

    Man, you don't get it, right? Ok, let me repeat it a last time: you are using redirection which is a Shell feature. Through Qt you are starting a process. So no Shell available, only cpio. Result: no redirection possible.

    Why don't you simply read the info page of cpio? It is clearly explained there how to use a file instead of redirection. For the impaired: it is the option -F[SPACE]FILENAME or --file=FILENAME
    There are 10 people in the world. Those who understand binary and those who don't.

  14. #13
    Join Date
    May 2006
    Posts
    32
    Thanks
    1
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to extract and compress a cpio archive file in Qt

    Hello Thomas,

    I did it that 3 days back. I could not post it back.
    its working fine.

    Thanks to all.
    Sarode
    Regards

  15. #14
    Join Date
    Jan 2006
    Location
    Socorro, NM, USA
    Posts
    29
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to extract and compress a cpio archive file in Qt

    Never mind; glad that it finally works.
    There are 10 people in the world. Those who understand binary and those who don't.

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.