-
-
Save RANUX/b54c254a12003d11b0821144704fa765 to your computer and use it in GitHub Desktop.
Python and Nodejs with subprocess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
import subprocess | |
if __name__ == '__main__': | |
ps = subprocess.Popen(['nodejs','ps2.js'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
out = ps.communicate(input='http://www.daum.net'.encode())[0] | |
print(out.decode('utf-8')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const http = require('http') | |
process.stdin.setEncoding('utf-8') | |
process.stdout.setEncoding('utf-8') | |
process.stdin.on('readable', () => { | |
const content = process.stdin.read() | |
if(!!content) { | |
http.get(content, (res) => { | |
if(res.statusCode >= 200 && res.statusCode < 400) { | |
let body = '' | |
res.on('data', (d) => body += d) | |
res.on('end', () => console.log(body)) | |
} else { | |
console.error(`[${res.statusCode}] ${res.statusMessage}`) | |
} | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment