sebastian
sebastian

Reputation: 179

Exact command for starting a batch file by using powershell

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.

Upvotes: 0

Views: 108

Answers (1)

Paul
Paul

Reputation: 5871

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

Upvotes: 1

Related Questions