Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stdout is Missing When Executed as Subprocess #4890

Closed
1 task done
chengzhuo5 opened this issue Apr 1, 2024 · 7 comments
Closed
1 task done

Stdout is Missing When Executed as Subprocess #4890

chengzhuo5 opened this issue Apr 1, 2024 · 7 comments
Milestone

Comments

@chengzhuo5
Copy link

  • I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options
git version 2.44.0.windows.1
cpu: x86_64
built from commit: ad0bbfffa543db6979717be96df630d3e5741331
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
** insert your machine's response here **
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.26090.112]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
> type "$env:USERPROFILE\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

Editor Option: VisualStudioCode
Custom Editor Path:
Default Branch Option:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: LFOnly
Bash Terminal Option: ConHost
Git Pull Behavior Option: Merge
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Enabled
Enable Pseudo Console Support: Enabled
Enable FSMonitor: Enabled
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

No

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

PowerShell

I'm encountering an issue when executing Git as a subprocess, where I'm unable to receive any output.

Here's the code that fails to produce output:

const { exec, execSync, spawn } = require('child_process');
exec('git.exe --version', (error, stdout, stderr) => {
  console.log(error, stdout, stderr); // null, '', ''
});
execSync('git.exe --version', {
  stdio: 'pipe',
});

However, the following code does produce output:

execSync('git.exe --version', {
  stdio: 'inherit',
});

This issue is not specific to Node.js. I’ve encountered the same problem when executing Git as a subprocess using other languages like TCL/TK.

This issue is causing nearly all Git plugins to fail, including the official Git-Gui.

Any help or guidance on this issue would be greatly appreciated.

@dscho
Copy link
Member

dscho commented Apr 1, 2024

const { exec, execSync, spawn } = require('child_process');
exec('git.exe --version', (error, stdout, stderr) => {
console.log(error, stdout, stderr); // null, '', ''
});
execSync('git.exe --version', {
stdio: 'pipe',
});

You did not really say it, but this is a Node.js script.

It does work on my machine, though:

PS C:\me> node --version
v20.10.0
PS C:\me> node a1.js
null git version 2.44.0.windows.1

@dscho dscho added the unclear label Apr 1, 2024
@chengzhuo5
Copy link
Author

chengzhuo5 commented Apr 2, 2024

const { exec, execSync, spawn } = require('child_process');
exec('git.exe --version', (error, stdout, stderr) => {
console.log(error, stdout, stderr); // null, '', ''
});
execSync('git.exe --version', {
stdio: 'pipe',
});

You did not really say it, but this is a Node.js script.

It does work on my machine, though:

PS C:\me> node --version
v20.10.0
PS C:\me> node a1.js
null git version 2.44.0.windows.1

What is your Windows version? I tried it on both Win11 22621 and 26090 versions, neither worked.

@chengzhuo5
Copy link
Author

Well, I reinstalled Windows and it worked. I will continue to search for the cause of the problem. This issue is closed first.

@chengzhuo5
Copy link
Author

After I installed the isolated domain software (DACS) provided by my company, the issue recurred. I have reported this issue to the author of DACS and will continue to follow up on this issue.

@chengzhuo5
Copy link
Author

chengzhuo5 commented Apr 8, 2024

I found that the Windows Filtering Platform driver provided by the security software seems to have changed the buffer type of stdout from _IONBF to _IOFBF or _IOLBF, causing stdout to fail without manually calling fflush(stdout) when the buffer is not full. The contents of the output buffer. I will file a PR to manually call fflush(stdout) when git exits.

@chengzhuo5 chengzhuo5 reopened this Apr 8, 2024
@chengzhuo5
Copy link
Author

#4901

@dscho dscho added enhancement and removed unclear labels Apr 12, 2024
@dscho dscho added this to the Next release milestone Apr 12, 2024
@dscho
Copy link
Member

dscho commented Apr 12, 2024

/add relnote bug Apparently some anti-malware programs fiddle with the mode of stdout which can lead to problems because expected output is missing, which was fixed.

The workflow run was started

github-actions bot pushed a commit to git-for-windows/build-extra that referenced this issue Apr 12, 2024
Apparently some anti-malware programs fiddle with the mode of `stdout`
which [can lead to problems because expected output is
missing](git-for-windows/git#4890), which [was
fixed](git-for-windows/git#4901).

Signed-off-by: gitforwindowshelper[bot] <gitforwindowshelper-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants