c2w: Convert Any CLI Program to a Web Service

Dyx @ Jun 13, 2020 CST

You could install it by pip install c2w.

For example, you wrote a very advanced English-to-Chinese dict program entocn.

% entocn hello 

Start a Web service within one line.

% c2w -H entocn

You get entocn online on the port 8000 and people on the Internet can use it by visiting http://yourhost:8000/?hello and they get the corresponding Chinese word of hello in their browsers.

You may want to work with a mature Web server like Apache HTTPd. c2w provides CGI mode which can convert your program to a CGI script.


c2w --cgi entocn

Put the above script in the cgi-bin directory of your Web server and you get a CGI script which can translate English words to Chinese words.

c2w parses the query string, splits it by &, decodes the split list and sends them as the command line arguments to the target program.

The request body will be directly sent to the standard input of the target body and the standard output of the target program will be redirected to the browser.

Call c2w --help to see the usage. Visit the Github repository of c2w for more information.