Reputation: 6774
I have this this code for Android which is stuck at the synchronized statement. Even if i remove the process1.wait() i catch the exception.any help is appreciated?
private class LongOperation extends AsyncTask<String, Void, String>
{
@Override
protected String doInBackground(String... params)
{
try
{
Process process1 = new ProcessBuilder("sh", "/data/local/bin/tcpdump.sh").start();
synchronized(process1){
process1.wait();
}
}
catch (Exception e)
{
Log.e("Tcpdump function error", "Unable to capture the packets into the buffer");
}
return null;
}
/* (non-Javadoc)
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
@Override
protected void onPostExecute(String result)
{
try
{
StringBuffer output = new StringBuffer();
File file = new File("/data/local/bin/dump.txt");
BufferedReader br = new BufferedReader(new FileReader(file), 8 * 1024);
String line;
while ((line = br.readLine()) != null)
{
output.append(line + "\n");
}
tv.setText(output);
setContentView(tv);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see android.os.AsyncTask#onProgressUpdate(Progress[])
*/
@Override
protected void onProgressUpdate(Void... values)
{
}
}
The tcpdump.sh has this line tcpdump -c 10 > /data/local/bin/dump.txt
Upvotes: 3
Views: 10894
Reputation: 310860
Surely you are meaning to call Process.waitFor()?
Not wait()?
Upvotes: 3