child-subshell

1.0.3 • Public • Published

child-subshell

child-subshell is a library to create a new shell and run sequence of commands inside the shell. You also could run interactive command and send proper input text by monitoring the output from command.

Install

It uses unbuffer for flushing the console message. You should install it first with brew install homebrew/dupes/expect. To install the package, run npm i child-subshell

Usage

Here is a simple example for running commands. You could see the running result by setting setLogger on shell

const subshell = require('../src/wrapper');

const shell = subshell.shell();
const run = subshell.command(shell);

shell.setLogger((line) => console.log(line));

(async () => {
  await run('ls');
  await run('cd ..');
  await run('ls -al');
  await process.exit(0);
})();

The next example is an interactive commad demo. It calls the python and sending some formula

const subshell = require('../src/wrapper');

const shell = subshell.shell();
const run = subshell.command(shell);
const run_interactive = subshell.command_interactive(shell);

shell.setLogger((line) => console.log(line));

let python_commands = ['1+1', 'print "hello"', 'exit()'];

(async () => {
  await run('ls -al');
  await run_interactive('python', (line, input) => {
    if(line === '>>> ') {
      input(python_commands.shift());
    }
  });

  await run('ls -al');
  await process.exit(0);
})();

Readme

Keywords

none

Package Sidebar

Install

npm i child-subshell

Weekly Downloads

3

Version

1.0.3

License

ISC

Unpacked Size

30.6 kB

Total Files

12

Last publish

Collaborators

  • markkong318