问题描述
我正在编写代码以在node.js环境中创建在线c ++编译器.使用spawn
函数创建了一个子进程,该子进程将编译代码并执行并将输出发送回用户.但是我需要将输入发送到正在运行的c ++程序.我使用了child.stdin.write('data');
发送数据给孩子,但我认为程序中的cin
没有收到输入.
请帮助我将输入发送到正在运行的c ++代码.
谢谢.
I am writing code to create an online c++ compiler in node.js environment.Using spawn
function i created a child process which will compile the code and execute it and send the output back to the user.But i need to send input to the running c++ program . I used child.stdin.write('data');
for sending data to child but i think cin
in the program is not receiving the input .
Please help me to send the input to the running c++ code.
Thanks.
推荐答案
1.使用输入数据创建文件.
2.创建ReadStream
打开输入文件.
3.将ReadStream
和childprocess.stdin
放在管道上.
1.Create a file with input data.
2.Create a ReadStream
opening input file.
3.Pipe the ReadStream
with childprocess.stdin
.
file=fs.createReadStream('input.txt',{encoding:'utf8'});
file.pipe(childprocess.stdin);
这对我有用.
这篇关于在node.js中将输入数据发送到子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!