Команда z storage blob upload завершается неудачно со странным исключением, когда вызывается из исполняемого файла Windows - PullRequest
0 голосов
/ 02 апреля 2019

Ниже приведена команда az storage blob upload в сценарии powershell с именем upload_file.ps1, которая загружает файл в хранилище Azure в виде большого двоичного объекта.

$ErrorActionPreference = "Stop"
# Blob connection string parsed from a secure string
az storage blob upload --container-name "ftp" --connection-string "$blobConnStr" --name "testfile.txt" --file testfile.txt

Нет проблем при выполнении этого скрипта напрямую.Но после преобразования его в исполняемый файл Windows upload_file.exe с помощью этого инструмента PS2EXE выполнение завершается неудачно, за исключением следующих случаев.

ERROR: System.Management.Automation.PSInvocationStateInfo
ERROR: System.Management.Automation.ActionPreferenceStopException: The running command stopped because the preference variable "
ErrorActionPreference" or common parameter is set to Stop: System.Management.Automation.RemoteException
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.DlrScriptCommandProcessor.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToPro
cess)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
ERROR: Failed
ERROR: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: S
ystem.Management.Automation.RemoteException

Чтобы распечатать сообщение более подробного уровня, я изменил ps2exe.ps1 скрипт немного как ниже.

if (powershell.InvocationStateInfo.State == PSInvocationState.Failed) {
  ui.WriteErrorLine(powershell.InvocationStateInfo.ToString());
  ui.WriteErrorLine(powershell.InvocationStateInfo.Reason.ToString());
  ui.WriteErrorLine(powershell.InvocationStateInfo.State.ToString());
  ui.WriteErrorLine(powershell.InvocationStateInfo.Reason.Message);
}

Не уверен, существует ли проблема совместимости между CLI Azure и исполняемыми файлами Windows.Был бы очень признателен, если бы кто-то с опытом работы с Windows мог бы рассказать нам об этом.

...