NodeJS Child Process gibt einen leeren Ausgang für Git -Befehl an, um die Anzahl von Commits zu erhaltenJavaScript

Javascript-Forum
Anonymous
 NodeJS Child Process gibt einen leeren Ausgang für Git -Befehl an, um die Anzahl von Commits zu erhalten

Post by Anonymous »

Wenn ich diese 2 Git -Anweisungen ausführe, sehe ich eine Ausgabe auf der Konsole:
Befehl 1 (um die Anzahl der hinzugefügten Zeilen zu erhalten/gelöscht):
git -C "/path/to/my/repo" log --author="me@myemail.com" -i --since="2024-06-01" --until="2025-12-31" --pretty=tformat: --numstat | awk '{added += $1; deleted += $2} END {print added, deleted}'
< /code>
Ausgabe: < /p>
374 0
< /code>
Befehl 2 (um die Anzahl von Commits zu erhalten): < /p>
git -C "/path/to/my/repo" shortlog -sne --author="me@myemail.com" -i --since="2024-06-01" --until="2025-12-31" | awk '{print $1}'
< /code>
Ausgabe: < /p>
1
< /code>
Wenn ich NodeJs verwende, um einen untergeordneten Prozess zu starten, den Befehl git auszuführen und die Ausgabe auf der Konsole anzuzeigen, erzeugt der Befehl 1 die erwartete Ausgabe, aber Befehl 2 erzeugt eine leere Ausgabe.const { execSync } = require('child_process');

const command = `git -C "/path/to/my/repo" log --author="me@myemail.com" -i --since="2024-06-01" --until="2025-12-31" --pretty=tformat: --numstat | awk '{added += $1; deleted += $2} END {print added, deleted}'`
const output = execSync(command, { encoding: 'utf-8' }).trim();
console.log(output);
< /code>
Ausgabe: < /p>
374 0

< /code>
mit Befehl 2: < /p>
const { execSync } = require('child_process');

const command = `git -C "/path/to/my/repo" shortlog -sne --author="me@myemail.com" -i --since="2024-06-01" --until="2025-12-31" | awk '{print $1}'`
const output = execSync(command, { encoding: 'utf-8' }).trim();
console.log(output);
< /code>
Ausgabe: < /p>

< /code>
In meinem tatsächlichen Programm muss ich die Ausgabe des GIT -Befehls in JavaScript verarbeiten. Was mache ich bei NodeJs mit dem zweiten Befehl falsch?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post