1

I pass , string parameter to .ps script as an argument , but when the print value shows, when it passes as my file path it will not take. need some expert help to fix this.

    # Main-function
function main($scriptName='test') {
    #run test-suit
    run-test-suit1
    exit
}

# start run apache test plan
function run-test-suit1
{
    #start to run test plan
    New-Variable -Name 'scriptName' -Value $scriptName".bat"
    Write-host "Start Run" $scriptName "test suit";
    C:/workspace/D/Int_Module/$scriptName  -NoNewWindow -Wait

}

main @args

Out Put: enter image description here

test.bat

    @ECHO OFF

echo Read and set host

set message=Load test name not Provided 
echo %message%
uma
  • 1,477
  • 3
  • 32
  • 63
  • 1
    In short: An executable path that is quoted or contains variable references must - for syntactic reasons - be invoked with `&`, the [call operator](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Operators#call-operator-); see [this answer](https://stackoverflow.com/a/57678081/45375) to the linked duplicate for details. – mklement0 Oct 09 '21 at 18:50
  • 1
    Therefore: `C:/workspace/D/Int_Module/$scriptName ...` -> `& C:/workspace/D/Int_Module/$scriptName ...` (all on one line). – mklement0 Oct 09 '21 at 18:51
  • 1
    As an aside: There's normally no reason to use [`New-Variable`](https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/new-variable) to create variables - `$scriptName = "$scriptName.bat"` will do. – mklement0 Oct 09 '21 at 18:54
  • 1
    @mklement0 it worked with & – uma Oct 10 '21 at 03:46

1 Answers1

1

You can try to invoke cmd from powershell:

# start run apache test plan
function run-test-suit1()
{
    #start to run test plan
    New-Variable -Name 'scriptName' -Value $scriptName".bat"
    Write-host "Start Run" $scriptName "test suit";

    cmd.exe /c C:/workspace/D/Int_Module/$scriptName -NoNewWindow -Wait 
}
  • 1
    Calling via `cmd.exe /c` is a viable workaround, but the proper solution is to use `&`, the [call operator](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Operators#call-operator-) – mklement0 Oct 09 '21 at 18:53