To run a shell script from Typescript, you can make use of the child_process
module, specifically the spawn
function. Here's an example code snippet:
index.ts338 chars16 lines
In the spawn
function, the first argument is the command to run (in this case, sh
to run the shell script), and the second argument is an array of command line arguments to pass to the command (in this case, just the path to the shell script).
The code then sets up event handlers for the stdout
, stderr
, and close
events emitted by the child process. The stdout
and stderr
events will capture any output generated by the script while it's running, and the close
event will be emitted when the script completes.
gistlibby LogSnag