std.process - avoid interaction with parent shell
Steven Schveighoffer
schveiguy at gmail.com
Mon Jul 20 21:44:31 UTC 2020
On 7/20/20 5:24 PM, H. S. Teoh wrote:
> On Mon, Jul 20, 2020 at 04:55:52PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote:
>> I am doing some scripting via D, and using std.process.execute to git
>> clone things.
>>
>> I don't want any user interaction. Occasionally, I get a repository
>> that no longer exists (404). Then git comes up and asks for a
>> username/password. I want it to just fail. Apparently git has no
>> option to be non-interactive, it supposedly checks stdin to see if
>> it's a tty, and only errors if it's not.
>
> Try --no-pager perhaps? Not sure if that would help, since this isn't
> technically a pager that's prompting you.
>
> Another way is to take a look at std.process.execute's implementation. I
> believe it's just a wrapper around spawnProcess. What you want is to
> adapt that implementation so that it closes stdin before fork-n-exec'ing
> git; that should stop any prompts.
I ran the git command from the shell directly with < /dev/null and it
still can ask for username/password. I don't know if it's possible to
prevent it.
>
> One thing to be aware of is that it may not necessarily be git itself
> that's prompting you; it could be a helper program like a password
> manager that creates the prompt. In that case you probably have to find
> out what it is, and disable it somehow (usually by overriding some
> environment variable that gets passed to the git child process).
I think you might be right. I don't know how it's accessing my terminal,
but clearly it can keep doing so even without any handles open. I'm even
using ctrl-D and it continues to come up with prompts and wait for input.
I was able to solve it by backgrounding the process, and then quitting
the parent shell, then it had no option but to error ;)
I'm still interested in knowing how this works, if anyone knows.
Searching for things like "how does git access my terminal when I closed
stdin" doesn't give me much information.
-Steve
More information about the Digitalmars-d-learn
mailing list