2

我们az storage blob upload在名为的 powershell 脚本中有以下命令,该脚本upload_file.ps1将文件作为 blob 上传到 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

直接执行这个脚本是没有问题的。upload_file.exe但在使用此PS2EXE工具将其转换为 Windows 可执行文件后,执行失败并出现以下异常。

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);
}

不确定 Azure CLI 和 Windows 可执行文件之间是否存在任何兼容性问题。如果有 Windows 经验的人能就此启发我们,将不胜感激。

4

0 回答 0