在天蓝色批处理中创建 .ps1 启动任务时出现意外令牌错误

Unexpected token error creating a .ps1 startup task in azure batch

我正在尝试 运行 批量 StartTask 中的 powershell 脚本,但遇到错误。下面是我在创建pool startTask时出错的代码:

def create_pool(batch_service_client, pool_id, resource_files, node_os_family):
    print('Creating pool [{}]...'.format(pool_id))
    task_commands = [
        'copy $AZ_BATCH_TASK_WORKING_DIR/python_tutorial_task.py $AZ_BATCH_NODE_SHARED_DIR',
        'powershell.exe -command set-executionpolicy remotesigned',
        "powershell.exe -command $AZ_BATCH_NODE_STARTUP_DIR" + "\" + "PrepPython.ps1",
        'pip install azure-batch',
        'pip install azure-storage',
        'pip install cryptography']
    ... ...

后来我将这些命令打包成一行,并在前面附加了 "cmd.exe /c"。但这没有用,并不断引发以下错误:

At line:1 char:27
+ $AZ_BATCH_NODE_STARTUP_DIR\PrepPython.ps1
+                           ~~~~~~~~~~~~~~~
Unexpected token '\PrepPython.ps1' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx 
   ception
    + FullyQualifiedErrorId : UnexpectedToken
... ...

有人对此有想法吗?

我 运行 遇到了类似的问题。下面是我必须如何组成 "command" 值,但使用你的变量:

cmd /c powershell.exe %AZ_BATCH_NODE_STARTUP_DIR%\PrepPython.ps1

您似乎是 运行 您在 Windows 上的命令。您的环境变量格式不正确 - 您使用的是 Linux $VAR 格式,而它们应该是 %VAR% 格式。此外,您的目录分隔符斜杠似乎是混合的(例如,您的第一个复制命令)。