Skip to content

Commit a07c992

Browse files
author
Jianghao Lu
committed
Merge pull request Azure#892 from ljhljh235/release-0.9.8
Fix for non-interactive scenario
2 parents 13e78b5 + c66a1e5 commit a07c992

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -254,28 +254,27 @@ protected void SaveDataCollectionProfile()
254254

255255
protected bool CheckIfInteractive()
256256
{
257-
if (this.Host == null || this.Host.UI == null || this.Host.UI.RawUI == null)
258-
{
259-
return false;
260-
}
261-
262257
bool interactive = true;
263-
try
258+
if (this.Host == null || this.Host.UI == null || this.Host.UI.RawUI == null)
264259
{
265-
var test = this.Host.UI.RawUI.KeyAvailable;
260+
interactive = false;
266261
}
267-
catch (HostException ex)
262+
else
268263
{
269-
if (ex.Message.StartsWith("A command that prompts the user failed"))
264+
try
270265
{
271-
interactive = false;
266+
var test = this.Host.UI.RawUI.KeyAvailable;
272267
}
273-
else
268+
catch
274269
{
275-
throw ex;
270+
interactive = false;
276271
}
277272
}
278273

274+
if (!interactive && !_dataCollectionProfile.EnableAzureDataCollection.HasValue)
275+
{
276+
_dataCollectionProfile.EnableAzureDataCollection = false;
277+
}
279278
return interactive;
280279
}
281280

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

291-
if (CheckIfInteractive() && !_dataCollectionProfile.EnableAzureDataCollection.HasValue)
290+
if (!_dataCollectionProfile.EnableAzureDataCollection.HasValue && CheckIfInteractive())
292291
{
293292
WriteWarning(Resources.DataCollectionPrompt);
294293

0 commit comments

Comments
 (0)