1

I am using NodeJS to run webots by command line and have redirected the stdout too the node terminal. My problem is that I want to trigger an event based on a console log. I tried redirecting the stdout of the command to another file, but this didn't seem to work.

This is the console output

INFO: sumo_example_two: Starting controller: python.exe -u sumo_example_two.py
INFO: sumo_supervisor: Starting controller: python.exe -u sumo_supervisor.py
robot2
INFO: sumo_example_one: Terminating.
INFO: sumo_example_two: Terminating.
INFO: sumo_supervisor: Terminating.
stdout:

I want to extract 'robot2'.

1 Answer 1

1

I have just tested and the following snippet works fine for me:

const { spawn } = require('child_process');
const ls = spawn('webots', ['--stdout']);

ls.stdout.on('data', (data) => {
  console.log(`stdout: ${data}`);

  // Process `data` as you prefer, something like
  //
  //   if (data.includes('robot2')) {
  //     something()
  //   }
});

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.