1

i have the following code:

'use strict';

// const exec = require('child_process').exec
var brainfuck = require('brainfuck')
let source = '>,[>,]<[.<]'
brainfuck.exec(source, function(err, output) {
    console.log(process.argv)
    console.log(output)
})

it is an brainfuck interpreter, that take inputs until a 'null' value is passed, so the code stops, then all code is reversed, printing to user.

when i run, i'm asked to pass values from TERMINAL, i do want to automate this inputs without 'human interation', as i wanna run thousands of tests, so my code will decide what to pass as inputs when asked.

enter image description here

enter image description here

EDIT3: brainfuck interpreter i'm using: github.com/rajkissu/brainfuck

which is a javascript interpreter

eeerrrttt
  • 549
  • 2
  • 7
  • 24
  • 1
    Can you provide a link to the brainfuck module you're using? Maybe it provides a way to supply alternate input. As far as I can tell, `node.js` doesn't have a built-in way of redirecting stdin. – Barmar Mar 14 '20 at 05:07
  • https://github.com/rajkissu/brainfuck – eeerrrttt Mar 14 '20 at 05:12
  • 1
    Unfortunately, that implementation is hard-coded to use `process.stdin`, and node.js doesn't provide a way to redirect that itself. – Barmar Mar 14 '20 at 05:50
  • sugestions? I also have some interpreters in c++ which use some different flux, but, also working not as expected. – eeerrrttt Mar 14 '20 at 05:52
  • the hard code is here: https://github.com/rajkissu/brainfuck/blob/master/lib/brainfuck.js – eeerrrttt Mar 14 '20 at 05:53
  • I know you don't like it, but my best suggestion is to write a simple shell script to run node.js with input redirected from a string. – Barmar Mar 14 '20 at 05:53
  • 1
    Either that or modify the brainfuck implementation to allow you to provide the input as a parameter instead of reading it from process.stdin. – Barmar Mar 14 '20 at 05:54
  • Here is my second interpreter i'm using: https://github.com/fabianishere/brainfuck – eeerrrttt Mar 14 '20 at 05:54
  • I need to pass the inputs inside the code, as i'll run it several hundred times in neural network – eeerrrttt Mar 14 '20 at 05:55
  • Can't you do that with a loop in a shell script? – Barmar Mar 14 '20 at 05:55
  • None of these brainfuck implementations has a way to redirect input themselves, it needs to be done before calling them. – Barmar Mar 14 '20 at 05:56
  • this would decrease a lot the performance. const { spawnSync } = require('child_process'); let child = spawnSync('brainfuck', ['-e', '>,[>,]<[.<]'], { input: 'hello' }) console.log('stdout ', child.stdout); here is my code running with the second interpreter (c++) written – eeerrrttt Mar 14 '20 at 05:56
  • i can pass the input in the second interpreter, but result is: stdout (just the first input "h") – eeerrrttt Mar 14 '20 at 05:59
  • i would need to pass many inputs, 1 input each time and then pass a ^@ (null) character to finish loop – eeerrrttt Mar 14 '20 at 06:00
  • Sorry, I give up. – Barmar Mar 14 '20 at 06:00
  • i could solve the problem with the second interpreter, the one i posted here in the commentaries, just changed { input: 'hello' } to { input: 'h\ne\nl\nl\no' } – eeerrrttt Mar 14 '20 at 17:45

0 Answers0