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

Can't redirect Process output when the process spawn a child. #42127

Closed
danfma opened this issue Sep 11, 2020 · 4 comments
Closed

Can't redirect Process output when the process spawn a child. #42127

danfma opened this issue Sep 11, 2020 · 4 comments

Comments

@danfma
Copy link

danfma commented Sep 11, 2020

Description

On Linux, I have tried to use the Process to spawn a new process to interact/manipulate with its output. However, I realized that if the process spawns a child process, on the same shell, you won't be able to retrieve the output of the child process. Is that the expected behaviour? Is there a way to do that?

Example:

var process = new Process
{
    StartInfo = new ProcessStartInfo("git", "fetch --all")
    {
        UseShellExecute = false,
        CreateNoWindow = true,
        RedirectStandardInput = true,
        RedirectStandardOutput = true
    }
};

process.Start();
process.OutputDataReceived += HandleUsernameRequest(process.StandardInput);
process.OutputDataReceived += HandlePasswordRequest(process.StandardInput);
process.BeginOutputReadLine();

The process will capture the first line output "Fetching origin", but not the line that requires to enter the username.

So, this was the output (the second line is not being captured):

Output: Fetching origin
Username for 'https://www.ve-smartapps.bt.com':

However, I was expecting:

Output: Fetching origin
Output: Username for 'https://www.ve-smartapps.bt.com':

Configuration

  • Which version of .NET is the code running on? 5.0.100-preview.8.20417.9
  • What OS and version, and what distro if applicable? Ubuntu 20.04
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? No.

Regression?

The same happens on .NET Core 3.1.

Other information

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Diagnostics.Process untriaged New issue has not been triaged by the area owner labels Sep 11, 2020
@ghost
Copy link

ghost commented Sep 11, 2020

Tagging subscribers to this area: @eiriktsarpalis, @jeffhandley
See info in area-owners.md if you want to be subscribed.

@tmds
Copy link
Member

tmds commented Sep 14, 2020

@danfma this is beyond .NET control. git doesn't read the password from standard in, instead it opens up a terminal to prompt for the password. Maybe you find some inspiration here: https://stackoverflow.com/questions/31218599/supplying-a-password-to-git-in-a-bash-script.

@danfma
Copy link
Author

danfma commented Sep 14, 2020

@danfma this is beyond .NET control. git doesn't read the password from standard in, instead it opens up a terminal to prompt for the password. Maybe you find some inspiration here: https://stackoverflow.com/questions/31218599/supplying-a-password-to-git-in-a-bash-script.

Thank you, man! I will give a look! I have tried to spawn the terminal instead of the git directly, but it didn't work as well!

@eiriktsarpalis
Copy link
Member

Sounds like we can close this. Thanks @tmds

@jeffhandley jeffhandley removed the untriaged New issue has not been triaged by the area owner label Sep 17, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants