Neville Nazerane
Neville Nazerane

Reputation: 7039

passing a second parameter in a batch file

I have a file hello.bat with the following code:

echo first: %1 and second: %2 > me.txt

I am trying to call this using powershell. When I pass the first parameter it works well:

 start-process hello test

However when i try to pass the second parameter like this:

 start-process hello test test2

I get this error:

Start-Process : A positional parameter cannot be found that accepts argument 'test2'

Upvotes: 1

Views: 734

Answers (2)

Olaf
Olaf

Reputation: 5242

I don't know why you're starting a command line from a command line but I think this should work:

Start-Process -FilePath $env:ComSpec -ArgumentList "/c hello.bat test test2"

Don't you think it's time to replace cmd with Powershell?

You might change your bat file as well:

echo %1 > me.txt
echo %2 >> me.txt

Upvotes: 0

Fsittius
Fsittius

Reputation: 160

You can just try pass the arguments using a comma like this:

start-process hello test,test2

or

start-process hello "test test2"

If you want to know more you can read the documentation here.

Upvotes: 1

Related Questions