Skip to content

Fix for non-interactive scenario #892

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

Merged
merged 1 commit into from
Sep 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/Common/Commands.Common/AzurePSCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,28 +254,27 @@ protected void SaveDataCollectionProfile()

protected bool CheckIfInteractive()
{
if (this.Host == null || this.Host.UI == null || this.Host.UI.RawUI == null)
{
return false;
}

bool interactive = true;
try
if (this.Host == null || this.Host.UI == null || this.Host.UI.RawUI == null)
{
var test = this.Host.UI.RawUI.KeyAvailable;
interactive = false;
}
catch (HostException ex)
else
{
if (ex.Message.StartsWith("A command that prompts the user failed"))
try
{
interactive = false;
var test = this.Host.UI.RawUI.KeyAvailable;
}
else
catch
{
throw ex;
interactive = false;
}
}

if (!interactive && !_dataCollectionProfile.EnableAzureDataCollection.HasValue)
{
_dataCollectionProfile.EnableAzureDataCollection = false;
}
return interactive;
}

Expand All @@ -288,7 +287,7 @@ protected void PromptForDataCollectionProfileIfNotExists()
// Initialize it from the environment variable or profile file.
InitializeDataCollectionProfile();

if (CheckIfInteractive() && !_dataCollectionProfile.EnableAzureDataCollection.HasValue)
if (!_dataCollectionProfile.EnableAzureDataCollection.HasValue && CheckIfInteractive())
{
WriteWarning(Resources.DataCollectionPrompt);

Expand Down