Run Linux commands on android

Source: Internet
Author: User

Run Linux commands on android

Process localProcess = runtime.getruntime(cmd.exe c (su );

This Code grants root privileges.

OutputStream localOutputStream = localProcess. getOutputStream ();

DataOutputStream localDataOutputStream = new DataOutputStream (localOutputStream );

Obtain the output stream from the Process object, and then we can execute the Linux Command.

LocalDataOutputStream. writeBytes (String str );

Str is a variable of the String type. Note that there is a line break at the end of str.

For example, String str = mkdir/mnt/sdcard/zhycheng;

 

InputStream localInputStream = localProcess. getInputStream ();

DataInputStream localDataInputStream = new DataInputStream (localInputStream );

The two codes get the output stream.

For example, String out = localDataInputStream. ReadLine ();

This is output from the console

Call after each output

LocalDataOutputStream. flush ();

Also call localProcess. waitFor ();

Call the test command int I = execRootCmdSilent (echo test) to determine whether the root permission is obtained. If I is not equal to-1, the root permission is obtained.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.