1

I have the following simple Windows batch script:

@echo off

echo Parameter 1: "%~1"
echo Parameter 2: "%~2"

When I execute it from the Windows command line (cmd) I get the following desired output:

C:\windows-script.bat "a=1" b
Parameter 1: "a=1"
Parameter 2: "b"

I now would like to execute the same script from a Cygwin bash command line and get the same output. Unfortunately I was not able to achieve what I want. Here are three unsuccessful trials:

$ /cygdrive/c/windows-script.bat "a=1" b
Parameter 1: "a"
Parameter 2: "1"
$ /cygdrive/c/windows-script.bat 'a=1' b
Parameter 1: "a"
Parameter 2: "1"
$ /cygdrive/c/windows-script.bat '"a=1"' b
Parameter 1: "\"a"
Parameter 2: "1\"""

Any ideas how to execute the batch script from Cygwin bash in the desired way?

2
  • I'm posting this as a comment instead of an answer because I have no way of testing this, but would "a\=1" work? Or possibly "a^=1"? Commented Mar 29, 2021 at 15:48
  • @SomethingDark Unfortunately both options do not resolve the issue. Commented Mar 30, 2021 at 7:25

1 Answer 1

1

This is one way of running it :

$ cmd <<< 'C:\windows-script.bat "a=1" b'

The syntax of <<< is equivalent to typing :

cmd

then typing :

C:\windows-script.bat "a=1" b

For more detail on <<<, see man bash

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

5 Comments

Thanks a lot. This works well. I already tried $ cmd /c 'C:\windows-script.bat "a=1" b' but that does not work. Why do I need 3 times the redirection character?
And what should I do if I have to wait for the execution of the command?
Answered your first question in the post. What do you mean by your second question ?
I believe that $ cmd <<< 'command' will start the Windows command line interpreter, but does not wait for the finalization of the command. It immediately returns back to bash.
It does wait, you can try cmd <<< 'ping www.google.com'

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.