fix bug stdin pipe to wrong process
This commit is contained in:
@@ -6,11 +6,12 @@ let environment = require('../lib/sheebr/environment')
|
|||||||
let aliases = require("../lib/sheebr/aliases")
|
let aliases = require("../lib/sheebr/aliases")
|
||||||
let { spawn } = require('child_process')
|
let { spawn } = require('child_process')
|
||||||
|
|
||||||
//utiliser ce code au lieuxc de execSync permet d'afficher le stdout au fur et a mesure ce qui fait qu'on a les logs quand une application throw une erreur
|
//utiliser ce code au lieux de execSync permet d'afficher le stdout au fur et a mesure ce qui fait qu'on a les logs quand une application throw une erreur
|
||||||
async function spawnAndWait(cmd, option) {
|
async function spawnAndWait(cmd, option) {
|
||||||
const child = spawn(cmd, option)
|
const child = spawn(cmd, option)
|
||||||
|
|
||||||
child.stdout.pipe(process.stdout)
|
child.stdout.pipe(process.stdout)
|
||||||
|
child.stderr.pipe(process.stderr)
|
||||||
process.stdin.pipe(child.stdin)
|
process.stdin.pipe(child.stdin)
|
||||||
|
|
||||||
await new Promise((res, rej) => {
|
await new Promise((res, rej) => {
|
||||||
@@ -18,6 +19,7 @@ async function spawnAndWait(cmd, option) {
|
|||||||
res()
|
res()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
process.stdin.unpipe(child.stdin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -28,8 +30,8 @@ start()
|
|||||||
async function start(){
|
async function start(){
|
||||||
while(true){
|
while(true){
|
||||||
const input = await getline("sheebr> ");
|
const input = await getline("sheebr> ");
|
||||||
if(input == "exit") break;
|
if(input === "exit") break;
|
||||||
if(input == "") continue;
|
if(!input) continue;
|
||||||
else await evaluate(input);
|
else await evaluate(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
|
//@ts-check
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} str
|
||||||
|
* @returns { Promise<string> }
|
||||||
|
*/
|
||||||
async function getline(str) {
|
async function getline(str) {
|
||||||
process.stdout.write(str)
|
process.stdout.write(str)
|
||||||
process.stdin.resume();
|
process.stdin.resume()
|
||||||
process.stdin.setEncoding('utf8')
|
process.stdin.setEncoding('utf8')
|
||||||
let line = ""
|
let line = ""
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
@@ -19,7 +25,7 @@ async function getline(str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isAlpha(str){
|
function isAlpha(str){
|
||||||
return /^[a-zA-Z]*$/.test(str);
|
return /^[a-zA-Z]*$/.test(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user