'No such file or directory' when trying to copy a file from sdcard to system with Runtime.exec()?
<p>I want to copy a TTF file from SD card to /system/fonts and change its permissions.</p>

<p>Here is my code:</p>

<pre><code>try {
    Runtime.getRuntime().exec("su");
} catch (IOException e) {
    Log.e("Font", "su", e);
}
exec("cp /mnt/sdcard/some.ttf /system/fonts/DroidSans.ttf");
exec("chmod 644 /system/fonts/DroidSans.ttf");

void exec(String cmd) {
    Log.e("Font", cmd);
    try {
        ProcessBuilder pb = new ProcessBuilder(cmd);
        pb.redirectErrorStream(true);
        Process p = pb.start();
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = br.readLine()) != null)
            Log.e("Font", cmd + ": " + line);
        Log.e("Font", cmd + ": " + p.waitFor());
    } catch (Exception e) {
        Log.e("Font", cmd, e);
    }
}
</code></pre>

<p>Root permissions granted &amp; /system/fonts mounted R/W. However I still get the following exceptions:</p>

<pre><code>E/Font    ( 4120): java.io.IOException: Error running exec(). Command: [cp /mnt/sdcard/some.ttf /system/fonts/DroidSans.ttf] Working Directory: null Environment: [ANDROID_SOCKET_zygote=10, ANDROID_BOOTLOGO=1, EXTERNAL_STORAGE=/mnt/sdcard, ANDROID_CACHE=/cache, ANDROID_ASSETS=/system/app, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ASEC_MOUNTPOINT=/mnt/asec, LOOP_MOUNTPOINT=/mnt/obb, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/core-junit.jar, SD_EXT_DIRECTORY=/sd-ext, PHONE_STORAGE=/mnt/emmc, ANDROID_DATA=/data, LD_LIBRARY_PATH=/vendor/lib:/system/lib, ANDROID_ROOT=/system, ANDROID_PROPERTY_WORKSPACE=9,32768]
E/Font    ( 4120):      at java.lang.ProcessManager.exec(ProcessManager.java:224)
E/Font    ( 4120):      at java.lang.ProcessBuilder.start(ProcessBuilder.java:202)
E/Font    ( 4120):      at hh.font.FontManagerActivity.exec(FontManagerActivity.java:94)
E/Font    ( 4120):      at hh.font.FontManagerActivity.onContextItemSelected(FontManagerActivity.java:84)
E/Font    ( 4120):      at android.app.Activity.onMenuItemSelected(Activity.java:2209)
E/Font    ( 4120):      at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2831)
E/Font    ( 4120):      at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
E/Font    ( 4120):      at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
E/Font    ( 4120):      at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:137)
E/Font    ( 4120):      at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:873)
E/Font    ( 4120):      at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/Font    ( 4120):      at android.widget.ListView.performItemClick(ListView.java:3513)
E/Font    ( 4120):      at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849)
E/Font    ( 4120):      at android.os.Handler.handleCallback(Handler.java:587)
E/Font    ( 4120):      at android.os.Handler.dispatchMessage(Handler.java:92)
E/Font    ( 4120):      at android.os.Looper.loop(Looper.java:130)
E/Font    ( 4120):      at android.app.ActivityThread.main(ActivityThread.java:3835)
E/Font    ( 4120):      at java.lang.reflect.Method.invokeNative(Native Method)
E/Font    ( 4120):      at java.lang.reflect.Method.invoke(Method.java:507)
E/Font    ( 4120):      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
E/Font    ( 4120):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
E/Font    ( 4120):      at dalvik.system.NativeStart.main(Native Method)
E/Font    ( 4120): Caused by: java.io.IOException: No such file or directory
E/Font    ( 4120):      at java.lang.ProcessManager.exec(Native Method)
E/Font    ( 4120):      at java.lang.ProcessManager.exec(ProcessManager.java:222)
E/Font    ( 4120):      ... 21 more
</code></pre>

<p>I can execute these commands without a problem with adb shell so the paths should be OK.</p>

<p>Had spent many hours without a clue. Could somebody please help me out? Thanks a lot!</p>
