0

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?

user123
  • 231
  • 2
  • 12
  • Hi, thank you for your suggestion, but this still doesn't work. And the error message changes to: {The argument '$AZ_BATCH_NODE_STARTUP_DIR\PrepPython.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter.}. But I think there exists the file. – user123 Dec 06 '16 at 11:51
  • @Avshalom, Also, I don't think that changing '-command' to '-file' is the problem, because I tested a script on my local computer, both worked very well – user123 Dec 06 '16 at 11:54
  • can you try this: `powershell.exe -file "$AZ_BATCH_NODE_STARTUP_DIR\PrepPython.ps1"` – Avshalom Dec 06 '16 at 11:57
  • @Avshalom, do you mean "powershell.exe -file $AZ_BATCH_NODE_STARTUP_DIR\PrepPython.ps1" – user123 Dec 06 '16 at 12:01
  • Hi @Avshalom, I tried this, but the error message is still the same, do you have any other idea. I have been strugling with this problem for almost 2 weeks now, also with the help of azure support team. But even they couldn't get it correct for now. – user123 Dec 06 '16 at 12:18

2 Answers2

0

I was running into a similar issue. Below is how I had to compose the "command" value, but using your variables:

cmd /c powershell.exe %AZ_BATCH_NODE_STARTUP_DIR%\PrepPython.ps1
Richie
  • 1
0

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).

fpark
  • 2,304
  • 2
  • 14
  • 21