MilesDyson
MilesDyson

Reputation: 778

Execute shell commands in same process of your app

I'm trying to unmount and mount USB devices programmatically. I can do it in adb with these commands:

umount /mnt/usb1
mount -t vfat -o rw /dev/block/sdb /mnt/usb1

But when I try to execute these commands from my app it doesn't work. Here is the codes I use:

Process proc = Runtime.getRuntime().exec(
                    new String[] { "/system/xbin/su", "-c",
                            "umount /mnt/usb1" });
proc.waitFor();

Process pr = Runtime.getRuntime().exec(new String[] {
              "/system/xbin/su", "-c",
              "mount -t vfat -o rw /dev/block/sdb /mnt/usb1" });
pr.waitFor();

Description of exec() method says: "Executes the specified command and its arguments in a separate native process. " So I think that command works but in a different process. In the process which my app runs, nothing gets effected. So I want to execute these commands in the process that my app runs.

I can get the process ID, thanks to this question . Is there a way to use this process ID to call current process and execute shell commands?

Upvotes: 0

Views: 535

Answers (1)

Viswanath Lekshmanan
Viswanath Lekshmanan

Reputation: 10093

I think that is not possible, Because : can you execute the command to kill the process from the same process . So that will not be possible at this time,May be they will extend the Process to include limited restrictions.

Upvotes: 1

Related Questions