Skip to content
Permalink
Browse files

process, bugfix: use real pipe-like struct to initial stdio in proces…

…s. (#501)
  • Loading branch information...
richardo2016 authored and xicilion committed May 23, 2019
1 parent aaf9f31 commit 4272135dda41c6646fd7e7d98c872cf7050d1481
Showing with 56 additions and 3 deletions.
  1. +3 −3 fibjs/src/process/process.cpp
  2. +17 −0 test/process/exec.chargeable.js
  3. +36 −0 test/process_test.js
@@ -236,7 +236,7 @@ result_t process_base::get_stdin(obj_ptr<File_base>& retVal)
Isolate* isolate = Isolate::current();

if (!isolate->m_stdin)
isolate->m_stdin = new File(0);
isolate->m_stdin = new File(stdin);
retVal = isolate->m_stdin;

return 0;
@@ -247,7 +247,7 @@ result_t process_base::get_stdout(obj_ptr<File_base>& retVal)
Isolate* isolate = Isolate::current();

if (!isolate->m_stdout)
isolate->m_stdout = new File(1);
isolate->m_stdout = new File(stdout);
retVal = isolate->m_stdout;

return 0;
@@ -258,7 +258,7 @@ result_t process_base::get_stderr(obj_ptr<File_base>& retVal)
Isolate* isolate = Isolate::current();

if (!isolate->m_stderr)
isolate->m_stderr = new File(2);
isolate->m_stderr = new File(stderr);
retVal = isolate->m_stderr;

return 0;
@@ -0,0 +1,17 @@
var io = require('io')

var is = new io.BufferedStream(process.stdin)

var input = null
while (true) {
input = is.readLine()
if (input === '.exit') {
console.log('exit')
break
}

if (input)
console.log(`> your input is: ${input}`)
else
console.log(`> you input nothing`)
}
@@ -66,6 +66,42 @@ describe('process', () => {
assert.equal(bs.readLine(), "hello, exec1");
});

it("stdin/stdout stream", () => {
var bs = process.open(cmd, [path.join(__dirname, 'process', 'exec.chargeable.js')]);
var outputs = []

process.nextTick(() => {
var oline = null

while (true) {
oline = bs.stdout.readLine()
if (oline === 'exit') {
break
}

if (oline) {
outputs.push(oline)
}
}
});

process.nextTick(() => {
bs.stdin.writeLine('line1')
bs.stdin.writeLine('line2')
bs.stdin.writeLine('.exit')
})

bs.wait()

assert.deepEqual(
outputs,
[
`> your input is: line1`,
`> your input is: line2`,
]
)
});

it("run", () => {
assert.equal(process.run(cmd, [path.join(__dirname, 'process', 'exec.js')]), 100);
});

0 comments on commit 4272135

Please sign in to comment.
You can’t perform that action at this time.