powershellcmdsyntaxgitlab-cicommand-line-arguments

Change command which works in cmd.exe to work in powershell.exe


I have a command which works without issue in cmd.exe:

%TESTING_INSTALLATION_PATH%\\client\\batch.exe --log-level=error --run %CI_BUILDS_DIR%\\autotest\\jobs\\clear.py

But it doesn't work in PowerShell like this:

$TESTING_INSTALLATION_PATH\\client\\batch.exe --log-level=error --run $CI_BUILDS_DIR\\autotest\\jobs\\clear.py

But received this:

строка:1 знак:30
+ $TESTING_INSTALLATION_PATH\\client\\batch.exe --log-level=error  ...
+                             ~~~~~~~~~~~~~~~~~
Unexpected token "\\client\\batch.exe" ........................
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Solution

  • Therefore:

    # NOTE:
    #  & to invoke a path containing variable references.
    #  $env: to reference environment variables
    #  Single \ only.
    & $env:TESTING_INSTALLATION_PATH\client\batch.exe --log-level=error --run $env:CI_BUILDS_DIR\autotest\jobs\clear.py