Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

35 Zeilen
978 B

  1. import { spawn } from 'node:child_process';
  2. export function startProcess(command, args, options = {}) {
  3. const child = spawn(command, args, {
  4. cwd: options.cwd,
  5. env: { ...process.env, ...(options.env || {}) },
  6. shell: process.platform === 'win32',
  7. stdio: ['ignore', 'pipe', 'pipe'],
  8. });
  9. const output = [];
  10. child.stdout.on('data', (chunk) => output.push(chunk.toString()));
  11. child.stderr.on('data', (chunk) => output.push(chunk.toString()));
  12. child.once('exit', (code) => {
  13. if (code !== null && code !== 0) {
  14. output.push(`\nprocess exited with code ${code}\n`);
  15. }
  16. });
  17. return { child, output };
  18. }
  19. export async function stopProcess(child) {
  20. if (!child || child.killed) return;
  21. await new Promise((resolve) => {
  22. child.once('exit', resolve);
  23. child.kill(process.platform === 'win32' ? undefined : 'SIGTERM');
  24. setTimeout(() => {
  25. if (!child.killed) child.kill('SIGKILL');
  26. resolve();
  27. }, 5000).unref();
  28. });
  29. }