Skip to content

Instantly share code, notes, and snippets.

@RANUX
Forked from webstory/ps1.py
Created October 16, 2019 14:17
Show Gist options
  • Save RANUX/b54c254a12003d11b0821144704fa765 to your computer and use it in GitHub Desktop.
Save RANUX/b54c254a12003d11b0821144704fa765 to your computer and use it in GitHub Desktop.
Python and Nodejs with subprocess
#-*- 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'))
'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