Processbuilder abnormal CreateProcess error=2,?? Õ?» µ½?¶

Source: Internet
Author: User

The back of the pile of garbled so I know had to use Google to check the answer to the question, turned upside down on the Enlightenment.


First oneself in how to get the APK information, and then learned about the Processbuilder class, specific how to get the APK information, I also wrote an analysis of this kind of article:


public class Testprocess {public static void main (string[] args) {Processbuilder PB = new Processbuilder ();p B.redirecterro Rstream (true); try {Process p = pb.command ("C:/getapkinfo/aapt.exe D badging d:/new/test.apk"). Start (); BufferedReader br = new BufferedReader (New InputStreamReader (P.getinputstream (), "UTF-8")); String s = ""; while ((S=br.readline ()) = null) {SYSTEM.OUT.PRINTLN (s);}} catch (IOException e) {e.printstacktrace ();}}}

When the code was executed, it was reported
Java.io.IOException:Cannot Run Program "C:/getapkinfo/aapt.exe D": CreateProcess error=2,????? μ???

The error.


But it is possible to execute directly in a DOS window.



Change the code to

Process p = pb.command ("ipconfig"). Start ();

is performed normally. A whole bunch of answers to the back are all path problems. No, it's the wrong solution.


The Processbuider API is written to the it is not checked whether command corresponds to a valid operating system command. is not a system instruction and does not prompt.


Then inspired by an online answer and source, I tried to change the code to:

Process p = Pb.command ("C:/getapkinfo/aapt.exe D", "badging", "d:/new/test.apk"). Start ();

Yes, this is normal execution.


Why is it?

It seems that instructions are not recognized if there is a space between instructions without a separate string.

Process p = pb.command ("C:/getapkinfo/aapt.exe", "", "D", "badging", "d:/new/test.apk"). Start ();
This is normal execution, but the result of this execution is equivalent to typing in the DOS window: C:/getapkinfo/aapt.exe.


Then, the Ipconfig/all is able to output the details of the IP address.

But instead:

Process p = pb.command ("ipconfig//all"). Start ();

also reported the same mistake, here everyone will know where the error is.


There are spaces in the instruction that need to be separated by different strings.

Re-read the API for this method.

Public processbuilder command (String ... command)

command-A string array containing the program and its arguments

The visible directives and parameters are placed in a different string array, so the following will execute normally:

Process p = pb.command ("C:/getapkinfo/aapt.exe", "", "D", "badging", "d:/new/test.apk"). Start ();

Processbuilder abnormal CreateProcess error=2,?? Õ?» µ½?¶

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.