Skip to content

Commit

Permalink
Merge pull request #3 from Dj-Viking/windows-spawn
Browse files Browse the repository at this point in the history
Windows spawn
  • Loading branch information
rexim authored Jun 24, 2024
2 parents b351216 + c772d1c commit fadc493
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
*.map
.prettierignore
14 changes: 12 additions & 2 deletions watch.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
// @ts-check
const spawn = require('child_process').spawn;

/**
*
* @param {string} program
* @param {string[]} args
* @returns {ReturnType<typeof spawn>}
*/
function cmd(program, args) {
console.log('CMD:', program, args);
const p = spawn(program, args.flat()); // NOTE: flattening the args array enables you to group related arguments for better self-documentation of the running command
const spawnOptions = { "shell": true };
console.log('CMD:', program, args.flat(), spawnOptions);
const p = spawn(program, args.flat(), spawnOptions); // NOTE: flattening the args array enables you to group related arguments for better self-documentation of the running command
// @ts-ignore [stdout may be null?]
p.stdout.on('data', (data) => process.stdout.write(data));
// @ts-ignore [stderr may be null?]
p.stderr.on('data', (data) => process.stderr.write(data));
p.on('close', (code) => {
if (code !== 0) {
Expand Down

0 comments on commit fadc493

Please sign in to comment.