C # Call the jar package to compress JS

Source: Internet
Author: User

The compression library is the closure compiler provided by Google.

Https://developers.google.com/closure/compiler? Hl = ZH-CN

 

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. diagnostics; namespace testprocessdoscmd {class program {static void main (string [] ARGs) {PROCESS p = NULL; P = new process (); p. startinfo. filename = "cmd.exe"; p. startinfo. useshellexecute = false; p. startinfo. redirectstandardinput = true; p. startinfo. redirectstandardoutput = false; p. startinfo. redirects Tandarderror = false; p. startinfo. createnowindow = false; p. start (); string sresult = string. empty; string strcmd = "Java-jar compiler. jar -- Help "; // string strcmd = @" Java-jar compiler. jar -- js d: \ devsoft \ library \ compiler-Latest \ js_name.js -- js_output_file D: \ devsoft \ library \ compiler-Latest \ js_name_compressed_prog.js "; // The source file cannot be placed in the same location as the target file. // string strcmd = @ "Java-jar compiler. jar -- js d: \ devsoft \ Library \ compiler-Latest \ js_name_bak.js -- js_output_file D: \ devsoft \ library \ compiler-Latest \ js_name_bak.js "; // string strcmd =" Java-version "; p. standardinput. writeline (strcmd); // while (! P. standarderror. endofstream) // {// sresult = P. standarderror. readline (); // console. writeline (sresult); //} // P. standardinput. flush (); // while (! P. standardoutput. endofstream) // {// sresult = P. standardoutput. readline (); // console. writeline (sresult); //} p. standardinput. writeline ("exit"); p. waitforexit (); p. close (); console. writeline ("press any key to exit. "); console. readkey ();}}}

From: https://developers.google.com/closure/compiler/docs/api-tutorial1? Hl = ZH-CN

 
#! /Usr/bin/python2.4import httplib, urllib, sys # define the parameters for the POST request and encode them in # a URL-safe format. params = urllib. urlencode ([('js _ Code', sys. argv [1]), ('compilation _ level', 'whitespace _ only'), ('output _ format', 'text'), ('output _ info ', 'compiled _ Code'),]) # Always use the following value for the Content-Type header. headers = {"Content-Type": "application/X-WWW-form-urlencoded"} conn = httplib. httpconnection ('Closure -compiler.appspot.com ') Conn. request ('post', '/compile', Params, headers) response = Conn. getresponse () Data = response. read () print dataconn. close

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.