1

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'

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

works great. Any idea how to pass a parameter with a space? i tried "test 'test 2' " it takes the second parameter as test not test 2
yes, you can do it like that start-process hello "test","test 2"
0

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

6 Comments

I did try powershell first. I created ps1 files and tried running them in a couple of ways, but it kept giving me "not recognized" errors. This command finally worked with at least with one parameter
by the way your code isn't working. no errors. A window pops up and disappears. no changes to the txt file
So you might start your research a little more "bottom". What do you actually try to achieve?
... added a proper bat file in my answer. It works this way for me.
Is the name hallo.bat <=> hello.bat the issue?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.