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

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: NodeJS Child Process gibt einen leeren Ausgang für Git -Befehl an, um die Anzahl von Commits zu erhalten

by Anonymous » 17 Mar 2025, 02:05

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?

Top