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%
4
  • 1
    In short: An executable path that is quoted or contains variable references must - for syntactic reasons - be invoked with &, the call operator; see this answer to the linked duplicate for details. Commented Oct 9, 2021 at 18:50
  • 1
    Therefore: C:/workspace/D/Int_Module/$scriptName ... -> & C:/workspace/D/Int_Module/$scriptName ... (all on one line). Commented Oct 9, 2021 at 18:51
  • 1
    As an aside: There's normally no reason to use New-Variable to create variables - $scriptName = "$scriptName.bat" will do. Commented Oct 9, 2021 at 18:54
  • 1
    @mklement0 it worked with & Commented Oct 10, 2021 at 3:46

1 Answer 1

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 
}
Sign up to request clarification or add additional context in comments.

1 Comment

Calling via cmd.exe /c is a viable workaround, but the proper solution is to use &, the call operator

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.