how to run unix commands from java
<p>I want to execute some Unix commands from the java code.</p>

<p>I want to run logcat command from java code.</p>

<p>I am using the below code to do this:</p>

<pre><code>  Process p = Runtime.getRuntime().exec("logcat -v time -f /mnt/sdcard/abc.txt");
</code></pre>

<p>The above code is working perfectly.</p>

<p>The same way I want to run some other Unix commands .</p>

<p>I want to run  "WC -l"(read no.of lines in file) command and I want to store it out put in some integer.</p>

<p>Below is the code that I have written for this:</p>

<pre><code> Process p = Runtime.getRuntime().exec("wc -l /mnt/sdcard/abc.txt");
</code></pre>

<p>But it is throwing below exception.</p>

<pre><code>   08-19 05:34:53.457 W/System.err( 1269): java.io.IOException: Error running exec(). Command: [wc, -l, /mnt/sdcard/abc.txt] Working Directory: null Environment: null

   08-19 05:34:53.457 W/System.err( 1269):  at java.lang.ProcessManager.exec(ProcessManager.java:224)

   08-19 05:34:53.457 W/System.err( 1269):  at java.lang.Runtime.exec(Runtime.java:189)

   08-19 05:34:53.457 W/System.err( 1269):  at java.lang.Runtime.exec(Runtime.java:275)

   08-19 05:34:53.457 W/System.err( 1269):  at java.lang.Runtime.exec(Runtime.java:210)
</code></pre>

<p>Please help me what's the issue in this..</p>

<p>I have a file "abc.txt"  in SD card.</p>

<p>is it possible to execute "WC -l" command from java code of android.</p>

<p>If we can execute Unix commands from java code we can make file operations very easier.</p>
