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
Re: How to extract and compress a cpio archive file in Qt
Your approach was correct. What went wrong?
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
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.
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.
Code:
.....
void RunProcess::runProcess()
{
arguments << "-i < " << "archive file path";
proc1->start(program, arguments);
if(proc1->waitForFinished())
return;
}
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
Re: How to extract and compress a cpio archive file in Qt
Try
Code:
arguments << "-i" << "<" << "archive file path";
Re: How to extract and compress a cpio archive file in Qt
Hello,
Tried passing the arguments as you suggest.
Code:
QString program1
= "/usr/bin/cpio";
arguments1 << "-i" << "<" << "/tmp/rootfs/archivefile";
proc1->start(program1, arguments1);
if(proc1->waitForStarted())
qWarning("Not Started");
But still not able to execute the process. Here even the if condition will not be true.
Please clarify
Regards,
Sarode
Re: How to extract and compress a cpio archive file in Qt
Try what's being suggested in this post.
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.
Re: How to extract and compress a cpio archive file in Qt
Hi,
Tried the other option specified the following output.
Code:
arguments1 << "-i" << "<filename_with_absolute_path";
// other option
// arguments1 << "-i" << "<" << "filename_with_absolute_path";
proc1->start("/usr/bin/cpio", arguments1);
if(!proc1->waitForFinished())
qWarning("Returned");
connect(proc1, SIGNAL(started()), this, SLOT(readData()));
void Process::readData()
{
qWarning("Started");
}
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
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.
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
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
Re: How to extract and compress a cpio archive file in Qt
Never mind; glad that it finally works.