Answer the question
In order to leave comments, you need to log in
How to pass data to the input stream?
Suppose there is a python script that asks for input, like this:
def who():
name = input('You name\n')
print(name);
who()
const spawn = require('child_process').spawn;
const test = spawn('python3', ['test.py'])
test.stdout.on('data', (data) => {
console.log(data.toString('utf8'))
});
test.on('close', (code) => {
console.log(code);
});
Answer the question
In order to leave comments, you need to log in
test.stdin.write("Username");
here you can’t like a link to a stackoverflow
, so here’s an example
var spawn = require('child_process').spawn,
child = spawn('phantomjs');
child.stdin.setEncoding('utf-8');
child.stdout.pipe(process.stdout);
child.stdin.write("console.log('Hello from PhantomJS')\n");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question