0

I know this question has been asked before and I found a thread on here which almost gives me the solution I need.

Here is the link: How to run batch file using powershell

But this only works when I write out the full path. For example:

c:\Users\Administrator\Desktop\dcp_bearbeitet\start.bat -p c:\Users\Administrator\Desktop\dcp_bearbeitet\start.prop

What I want to reach is a solution which accepts a path with parameters, like this one here:

c:\Users\Administrator\Desktop\dcp_bearbeitet\$title\start.bat -p c:\Users\Administrator\Desktop\dcp_bearbeitet\$title\start.prop

Whereas $title contains the name of my file which I am using in this case. I know that I can create another parameter for the -p command and I know that this works, but unfortunately when I try the same method for the first command I always get an error message.

I hope you guys know a way to solve this problem.

Community
  • 1
  • 1
sebastian
  • 179
  • 1
  • 4
  • 10

1 Answers1

1

I think Invoke-Expression could help here. Just construct your path like you want it to be, for example:

$title = "file"
$path = "C:\Users\Administrator\Desktop\dcp_bearbeitet\$title\start.bat -p c:\Users\Administrator\Desktop\dcp_bearbeitet\$title\start.prop"

and then invoke it:

Invoke-Expression $path

Regards Paul

Paul
  • 5,524
  • 1
  • 22
  • 39
  • thank you, you saved my day. Until now I never knew what Invoke-Expression does, that is why I never tried it. I gave you the answer. – sebastian Jan 10 '14 at 10:48