2

In powershell, I need to pass a variable into a command in cmd prompt. It would take this structure, and yes I need to open command prompt.

Variable= 5 points
$prog="cmd.exe"  ''open cmd
$params=@("/C") 

But I'm confused about the third line- can someone demonstrate for me an example of passing a variable in that line with some other parameters?

1
  • 4
    why you need to pass a var to cmd ? any thing that you can do in cmd you can also do in powershell Commented Mar 21, 2016 at 14:20

1 Answer 1

3

Just list string variables (a sample without @() syntax):

$prog = "cmd.exe"
$path = "C:\Users\user\Documents"
$params = "/C", "dir", $path

& $prog $params

This will work fine too:

$args = "dir", "C:\Users\user\Documents"
& cmd /c $args
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.