Java uses Runtime.getruntime (). exec () to invoke the Python script and pass the reference __python

Source: Internet
Author: User
Tags python script
 
TODO: Execute Python script
            System.out.println ("Start Python");
            Parameters to be passed
            String a = "AAA", B = "BBB", C = "CCC", D = "ddd";
            System.out.println ("start;;;" + a);
            Set command line incoming parameter
            string[] args = new string[] {"Python", "c:\\users\\desktop\\test1.py", A, B, C, d};
            Process PR = runtime.getruntime (). exec (args);
            TODO: This method can only pass strings
//            Process PR = runtime.getruntime (). EXEC ("Python c:\\users\\desktop\\test1.py c:\\users\ \hpp\\desktop\\test1.mp4 ");

            BufferedReader in = new BufferedReader (New InputStreamReader (Pr.getinputstream ()));
            String Line;

            while (line = In.readline ())!= null) {
//Line                = Decodeunicode (line);
                System.out.println (line);
            In.close ();
            Pr.waitfor ();
            System.out.println ("End");

test1.py (test whether the parameters can be taken)
Import sys
print sys.argv[0]
print sys.argv[1] print
sys.argv[2] Print
sys.argv[3]
Print SYS.ARGV[4]


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.