none
Powershell - how it passes parameters to a program? RRS feed

  • Question

  • Dear experts,

    Sorry for a noob question but cannot figure out how to pass parameters to a program in powershell script.

    I try this:

    $VAR = "42 /s file `"foo moo`" "
    my.exe other $VAR
    I want of course that parameters will be "other", "42" "/s", "file", "foo moo".

    But my.exe gets these parameters: "other", "42 /s file foo" , "moo"

    echo $VAR shows: 

    42 /s file "foo moo"

    How to do this in powershell?

    Please don't advice to remove the $VAR, it is actually more complex and substitutes other variables. So the question is how to expand a variable in a sane, unix shell-compatible way.

    my.exe is a plain VC++ console program.

    -- pa




    • Edited by Pavel A Monday, July 6, 2020 6:54 PM
    Monday, July 6, 2020 6:44 PM

Answers

  • OK, found this solution (after way too much googling):

    start-process -NoNewWindow -filepath "my.exe" -args "other ${VAR}"

    That's ugly. Anything better?

    -- pa

    • Marked as answer by Pavel A Wednesday, July 8, 2020 12:40 AM
    Monday, July 6, 2020 8:03 PM

All replies

  • OK, found this solution (after way too much googling):

    start-process -NoNewWindow -filepath "my.exe" -args "other ${VAR}"

    That's ugly. Anything better?

    -- pa

    • Marked as answer by Pavel A Wednesday, July 8, 2020 12:40 AM
    Monday, July 6, 2020 8:03 PM
  • Ok thanks everyone , the picture is clear ;)  

    Wednesday, July 8, 2020 12:40 AM