需要 SVN 身份验证时获取 STDERR 输出失败 [英] Getting STDERR output fails when SVN authenticaion needed
问题描述
我正在尝试执行 svn update
命令,但由于我没有通过此命令传递用户名和密码,因此它要求我提供这些凭据.但是我需要记录这个命令的 STDERR 输出.
I am trying to do a svn update
command but as I have not passed the username and password with this command it asks me for those credentials. But I need to record the STDERR output of this command.
这就是现在发生的事情:
This is what is happening now :
record = `svn update 2>&1`
它输出:
Authentication realm: <https://url_of_repository:443> url_of_repository SVN Repository
Username:
它停止执行,因为它期望用户输入凭据.但是我想将上述输出记录为变量中的字符串,以便我可以将用户名和密码传递给它.我该怎么做.
And it stops execution as its expecting the user to type credentials. But I would like to record the above output as a string in a variable so that I can pass the username and password to it. How do I do it.
感谢您的帮助.
推荐答案
这可以通过在命令中传递 --non-interactive
参数来完成,这样它就不会提示输入身份验证凭据.
This can be done by passing the --non-interactive
argument with your command so that it does not prompt for authentication credentials.
所以在你的情况下:
output = `svn update "#{repo_path}" --non-interactive 2>&1`
check_authentication = output.include?("Authentication failed")
如果认证失败,check_authentication
将返回 true
.
The check_authentication
will return true
if authentication failed.
这篇关于需要 SVN 身份验证时获取 STDERR 输出失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!