Running git clone from C# Process ignoring input for passphrase





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am attempting to run git clone through a C# process that also passes in the location of the SSH key.



The command:



cd C:\repo-location && SET GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i pathto.sshprivKey && git clone git@bitbucket.org:location.git


will prompt for the passphrase as expected, however, using Process seems to ignore it so I am getting a "git@bitbucket.org: Permission denied (publickey)." error immediately.



What is also interesting is the Process only returns from StandardError.



Here is the code:



ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = "C:\Git\git-cmd.exe";
pInfo.Arguements = "cd C:\repo-location && " +
"SET GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i "pathto.sshprivKey" && " +
"git clone git@bitbucket.org:location.git";
pInfo.RedirectStandardOutput = true;
pInfo.RedirectStandardError = true;
pInfo.RedirectStandardInput = true;
pInfo.UseShellExecute = false;
pInfo.CreateNoWindow = true;

Process process = Process.Start(pInfo);
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.ErrorDataReceived += new DataReceivedEventHandler((object sendingProcess, DataReceivedEventArgs outLine) => {
if (!string.IsNullOrEmpty(outLine.Data) && outLine.Data.StartsWith("Enter passphrase")) {
//Never hits here...
process.StandardInput.WriteLine(password);
}
});
process.OutputDataReceived += new DataReceivedEventHandler((object sendingProcess, DataReceivedEventArgs outLine) => {
if (!string.IsNullOrEmpty(outLine.Data) && outLine.Data.StartsWith("Enter passphrase")) {
//Never hits here...
process.StandardInput.WriteLine(password);
}
});


I tried other approaches to get SSH working with git config core.sshCommand but that doesn't even prompt for a passphrase when running from git-cmd.exe.



I prefer NOT to use ssh-agent since there can be a few keys I need to point to.



EDIT:



This can probably be boiled down to allowing a C# process to not eat the prompt for a passphrase and that is the issue with this. Does anyone have any solutions to that?



MORE INFO:



I noticed that even using the command in cmd.exe and redirecting stdout will also prevent interaction. But changing the code to not redirect still skips the interaction.










share|improve this question

























  • when you say when I am NOT running in C# ...does that mean when you are not debugging?

    – JohnB
    Nov 29 '18 at 2:42













  • I mean when I am running through git-cmd.exe. Or even in command prompt itself (if path is set or pointing to C:Gitcmdgit)

    – Jason
    Nov 29 '18 at 2:43













  • i see - maybe just comment your code to show the split better between the two scenarios - maybe it's just me but was not obvious at first - thanks

    – JohnB
    Nov 29 '18 at 2:45











  • Maybe still not clear. If I use Process to run the command, it will not prompt for the passphrase. It only prompts when running in command prompt or git bash.

    – Jason
    Nov 29 '18 at 3:16











  • are you running as admin on your machine? - maybe an aspect to bear in mind...

    – JohnB
    Nov 29 '18 at 3:17




















1















I am attempting to run git clone through a C# process that also passes in the location of the SSH key.



The command:



cd C:\repo-location && SET GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i pathto.sshprivKey && git clone git@bitbucket.org:location.git


will prompt for the passphrase as expected, however, using Process seems to ignore it so I am getting a "git@bitbucket.org: Permission denied (publickey)." error immediately.



What is also interesting is the Process only returns from StandardError.



Here is the code:



ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = "C:\Git\git-cmd.exe";
pInfo.Arguements = "cd C:\repo-location && " +
"SET GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i "pathto.sshprivKey" && " +
"git clone git@bitbucket.org:location.git";
pInfo.RedirectStandardOutput = true;
pInfo.RedirectStandardError = true;
pInfo.RedirectStandardInput = true;
pInfo.UseShellExecute = false;
pInfo.CreateNoWindow = true;

Process process = Process.Start(pInfo);
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.ErrorDataReceived += new DataReceivedEventHandler((object sendingProcess, DataReceivedEventArgs outLine) => {
if (!string.IsNullOrEmpty(outLine.Data) && outLine.Data.StartsWith("Enter passphrase")) {
//Never hits here...
process.StandardInput.WriteLine(password);
}
});
process.OutputDataReceived += new DataReceivedEventHandler((object sendingProcess, DataReceivedEventArgs outLine) => {
if (!string.IsNullOrEmpty(outLine.Data) && outLine.Data.StartsWith("Enter passphrase")) {
//Never hits here...
process.StandardInput.WriteLine(password);
}
});


I tried other approaches to get SSH working with git config core.sshCommand but that doesn't even prompt for a passphrase when running from git-cmd.exe.



I prefer NOT to use ssh-agent since there can be a few keys I need to point to.



EDIT:



This can probably be boiled down to allowing a C# process to not eat the prompt for a passphrase and that is the issue with this. Does anyone have any solutions to that?



MORE INFO:



I noticed that even using the command in cmd.exe and redirecting stdout will also prevent interaction. But changing the code to not redirect still skips the interaction.










share|improve this question

























  • when you say when I am NOT running in C# ...does that mean when you are not debugging?

    – JohnB
    Nov 29 '18 at 2:42













  • I mean when I am running through git-cmd.exe. Or even in command prompt itself (if path is set or pointing to C:Gitcmdgit)

    – Jason
    Nov 29 '18 at 2:43













  • i see - maybe just comment your code to show the split better between the two scenarios - maybe it's just me but was not obvious at first - thanks

    – JohnB
    Nov 29 '18 at 2:45











  • Maybe still not clear. If I use Process to run the command, it will not prompt for the passphrase. It only prompts when running in command prompt or git bash.

    – Jason
    Nov 29 '18 at 3:16











  • are you running as admin on your machine? - maybe an aspect to bear in mind...

    – JohnB
    Nov 29 '18 at 3:17
















1












1








1


1






I am attempting to run git clone through a C# process that also passes in the location of the SSH key.



The command:



cd C:\repo-location && SET GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i pathto.sshprivKey && git clone git@bitbucket.org:location.git


will prompt for the passphrase as expected, however, using Process seems to ignore it so I am getting a "git@bitbucket.org: Permission denied (publickey)." error immediately.



What is also interesting is the Process only returns from StandardError.



Here is the code:



ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = "C:\Git\git-cmd.exe";
pInfo.Arguements = "cd C:\repo-location && " +
"SET GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i "pathto.sshprivKey" && " +
"git clone git@bitbucket.org:location.git";
pInfo.RedirectStandardOutput = true;
pInfo.RedirectStandardError = true;
pInfo.RedirectStandardInput = true;
pInfo.UseShellExecute = false;
pInfo.CreateNoWindow = true;

Process process = Process.Start(pInfo);
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.ErrorDataReceived += new DataReceivedEventHandler((object sendingProcess, DataReceivedEventArgs outLine) => {
if (!string.IsNullOrEmpty(outLine.Data) && outLine.Data.StartsWith("Enter passphrase")) {
//Never hits here...
process.StandardInput.WriteLine(password);
}
});
process.OutputDataReceived += new DataReceivedEventHandler((object sendingProcess, DataReceivedEventArgs outLine) => {
if (!string.IsNullOrEmpty(outLine.Data) && outLine.Data.StartsWith("Enter passphrase")) {
//Never hits here...
process.StandardInput.WriteLine(password);
}
});


I tried other approaches to get SSH working with git config core.sshCommand but that doesn't even prompt for a passphrase when running from git-cmd.exe.



I prefer NOT to use ssh-agent since there can be a few keys I need to point to.



EDIT:



This can probably be boiled down to allowing a C# process to not eat the prompt for a passphrase and that is the issue with this. Does anyone have any solutions to that?



MORE INFO:



I noticed that even using the command in cmd.exe and redirecting stdout will also prevent interaction. But changing the code to not redirect still skips the interaction.










share|improve this question
















I am attempting to run git clone through a C# process that also passes in the location of the SSH key.



The command:



cd C:\repo-location && SET GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i pathto.sshprivKey && git clone git@bitbucket.org:location.git


will prompt for the passphrase as expected, however, using Process seems to ignore it so I am getting a "git@bitbucket.org: Permission denied (publickey)." error immediately.



What is also interesting is the Process only returns from StandardError.



Here is the code:



ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = "C:\Git\git-cmd.exe";
pInfo.Arguements = "cd C:\repo-location && " +
"SET GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i "pathto.sshprivKey" && " +
"git clone git@bitbucket.org:location.git";
pInfo.RedirectStandardOutput = true;
pInfo.RedirectStandardError = true;
pInfo.RedirectStandardInput = true;
pInfo.UseShellExecute = false;
pInfo.CreateNoWindow = true;

Process process = Process.Start(pInfo);
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.ErrorDataReceived += new DataReceivedEventHandler((object sendingProcess, DataReceivedEventArgs outLine) => {
if (!string.IsNullOrEmpty(outLine.Data) && outLine.Data.StartsWith("Enter passphrase")) {
//Never hits here...
process.StandardInput.WriteLine(password);
}
});
process.OutputDataReceived += new DataReceivedEventHandler((object sendingProcess, DataReceivedEventArgs outLine) => {
if (!string.IsNullOrEmpty(outLine.Data) && outLine.Data.StartsWith("Enter passphrase")) {
//Never hits here...
process.StandardInput.WriteLine(password);
}
});


I tried other approaches to get SSH working with git config core.sshCommand but that doesn't even prompt for a passphrase when running from git-cmd.exe.



I prefer NOT to use ssh-agent since there can be a few keys I need to point to.



EDIT:



This can probably be boiled down to allowing a C# process to not eat the prompt for a passphrase and that is the issue with this. Does anyone have any solutions to that?



MORE INFO:



I noticed that even using the command in cmd.exe and redirecting stdout will also prevent interaction. But changing the code to not redirect still skips the interaction.







c# git process






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 30 '18 at 8:41







Jason

















asked Nov 29 '18 at 2:40









JasonJason

10029




10029













  • when you say when I am NOT running in C# ...does that mean when you are not debugging?

    – JohnB
    Nov 29 '18 at 2:42













  • I mean when I am running through git-cmd.exe. Or even in command prompt itself (if path is set or pointing to C:Gitcmdgit)

    – Jason
    Nov 29 '18 at 2:43













  • i see - maybe just comment your code to show the split better between the two scenarios - maybe it's just me but was not obvious at first - thanks

    – JohnB
    Nov 29 '18 at 2:45











  • Maybe still not clear. If I use Process to run the command, it will not prompt for the passphrase. It only prompts when running in command prompt or git bash.

    – Jason
    Nov 29 '18 at 3:16











  • are you running as admin on your machine? - maybe an aspect to bear in mind...

    – JohnB
    Nov 29 '18 at 3:17





















  • when you say when I am NOT running in C# ...does that mean when you are not debugging?

    – JohnB
    Nov 29 '18 at 2:42













  • I mean when I am running through git-cmd.exe. Or even in command prompt itself (if path is set or pointing to C:Gitcmdgit)

    – Jason
    Nov 29 '18 at 2:43













  • i see - maybe just comment your code to show the split better between the two scenarios - maybe it's just me but was not obvious at first - thanks

    – JohnB
    Nov 29 '18 at 2:45











  • Maybe still not clear. If I use Process to run the command, it will not prompt for the passphrase. It only prompts when running in command prompt or git bash.

    – Jason
    Nov 29 '18 at 3:16











  • are you running as admin on your machine? - maybe an aspect to bear in mind...

    – JohnB
    Nov 29 '18 at 3:17



















when you say when I am NOT running in C# ...does that mean when you are not debugging?

– JohnB
Nov 29 '18 at 2:42







when you say when I am NOT running in C# ...does that mean when you are not debugging?

– JohnB
Nov 29 '18 at 2:42















I mean when I am running through git-cmd.exe. Or even in command prompt itself (if path is set or pointing to C:Gitcmdgit)

– Jason
Nov 29 '18 at 2:43







I mean when I am running through git-cmd.exe. Or even in command prompt itself (if path is set or pointing to C:Gitcmdgit)

– Jason
Nov 29 '18 at 2:43















i see - maybe just comment your code to show the split better between the two scenarios - maybe it's just me but was not obvious at first - thanks

– JohnB
Nov 29 '18 at 2:45





i see - maybe just comment your code to show the split better between the two scenarios - maybe it's just me but was not obvious at first - thanks

– JohnB
Nov 29 '18 at 2:45













Maybe still not clear. If I use Process to run the command, it will not prompt for the passphrase. It only prompts when running in command prompt or git bash.

– Jason
Nov 29 '18 at 3:16





Maybe still not clear. If I use Process to run the command, it will not prompt for the passphrase. It only prompts when running in command prompt or git bash.

– Jason
Nov 29 '18 at 3:16













are you running as admin on your machine? - maybe an aspect to bear in mind...

– JohnB
Nov 29 '18 at 3:17







are you running as admin on your machine? - maybe an aspect to bear in mind...

– JohnB
Nov 29 '18 at 3:17














0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53531052%2frunning-git-clone-from-c-sharp-process-ignoring-input-for-passphrase%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53531052%2frunning-git-clone-from-c-sharp-process-ignoring-input-for-passphrase%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks