I'm trying to run a powershell script in batch StartTask, but met an error. The following is the code where I went wrong when creating a 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']
... ...
And later I wrapped these commands into one line attaching "cmd.exe /c" ahead. But this didn't work, and kept raising the following error:
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
... ...
Anyone have ideas about this?
It appears that you are running your commands on Windows. Your environment variables are in an incorrect form - you are using Linux $VAR
format when they should be %VAR%
format. Also, it looks like your directory separator slashes are mixed (e.g., your first copy command).