java - Runtime.getRuntime().exec using PIPE in command -
i'm trying create splitted tar file , reading progress checking size of directory. (i cannot use pv command).
can explain me why if in tarservice.java change command to:
string cmd="su -c tar -cp -c /dev . | split -b 1g -a 3 - "+ fname;
the process in mainactivity never log until other process finished, while with:
string cmd="su -c tar -cpf " + fname + " -c /dev .";
it works!
take care in both cases tar file created.
mainactivitiy.java
public void startbackup(view v){ back= new backgroundtask().execute(); } private class backgroundtask extends asynctask<void, integer, string> { @override protected string doinbackground(void... arg0) { backup = new intent(mainactivity.this, tarservice.class); backup.putextra("fname", "test.tar); status=999; startservice(backup); while (status == 999) { try { process process = runtime.getruntime().exec("du -sk /dev"); bufferedreader bufferedreader = new bufferedreader( new inputstreamreader(process.getinputstream())); string line; while ((line = bufferedreader.readline()) != null) { log.d(tag,line); } } } } }
tarservice.java
protected void onhandleintent(intent i) { try{ location=i.getstringextra("location"); fname=i.getstringextra("fname"); // works string cmd="su -c tar -cpf " + fname + " -c /dev ."; process process = runtime.getruntime().exec(cmd); int code=process.waitfor(); intent intent = new intent("backupprocess"); intent.putextra("status", code); log.d(tag,integer.tostring(code)); localbroadcastmanager.getinstance(this).sendbroadcast(intent); } catch (ioexception e) { log.e(tag, e.getmessage()); throw new runtimeexception(e); } }
solved
there code error, passing du
command file name too, split filename different.
exec()
doesn't start shell, doesn't understand shell syntax redirections , pipes. if use shell syntax have start shell, via sh -c ...
.
Comments
Post a Comment