ballerina-lang icon indicating copy to clipboard operation
ballerina-lang copied to clipboard

Ballerina CLI as .bat file only cause command not found using Git Bash

Open Tim-Schwalbe opened this issue 6 years ago • 6 comments
trafficstars

Description: Ballerina CLI as .bat file only cause command not found using Git Bash

Steps to reproduce: Install Git Bash Install Ballerina execute ballerina in windows cmd execute ballerina in git bash

Affected Versions: Tested only on 0.990.2

Suggested Labels (optional): Ballerina CLI

Tim-Schwalbe avatar Feb 03 '19 12:02 Tim-Schwalbe

This is not a bug. We do not support this now.

suganyasuven avatar Jun 25 '21 05:06 suganyasuven

Hi, I would like to work on this, but I'm currently not sure how this can be fixed. I tried to run bal inside git bash and received the following error:

$ bal
bash: bal: command not found

On the other hand, if you run bal.bat inside git bash it works as expected:

 $ bal.bat version
Ballerina 2201.10.0 (Swan Lake Update 10)
Language specification 2024R1
Update Tool 1.4.3

So should I try to detect inside the bal script if it is running inside git bash and if so it should call bal.bat and also return the return code?

f-schnabel avatar Oct 03 '24 14:10 f-schnabel

Looking into my installation folder I noticed that there is no bal file inside the bin folder, only the bal.bat file. I think we would need to add a bal file also in the windows distribution so it can be found and used by git bash. This file should be the same as bal.bat. ~Otherwise it would also be feasable to directly rename the bal.bat file to bal for windows. This would also fix this issue~ bat scripts have to have this extension on windows, so we can't just rename it. We could create an alias and name the alias bal (see also: https://stackoverflow.com/a/75737360/14023216)

f-schnabel avatar Oct 03 '24 14:10 f-schnabel

Looking into my installation folder I noticed that there is no bal file inside the bin folder, only the bal.bat file. I think we would need to add a bal file also in the windows distribution so it can be found and used by git bash. This file should be the same as bal.bat. ~Otherwise it would also be feasable to directly rename the bal.bat file to bal for windows. This would also fix this issue~ bat scripts have to have this extension on windows, so we can't just rename it. We could create an alias and name the alias bal (see also: https://stackoverflow.com/a/75737360/14023216)

Actually, we can easily include the shell by removing this exclusion in the distribution build level but file name will be bal not bal.bat. We set up installtion here and have to figure out include shell seperately

keizer619 avatar Oct 10 '24 05:10 keizer619

Actually, we can easily include the shell by removing this exclusion in the distribution build level ...

This would include the Linux version of the shell script, but Git Bash also needs the Windows version of the shell, so the bal.bat file. It just doesn't automatically add the .bat like PowerShell or Command Prompt.

We would need some "proxy script" that just calls bal.bat but I'm not sure how.


If I'm adding the bal file from the .zip distribution and run it from Git Bash I get the following errors:

$ bal
cat: /c/Program: No such file or directory
cat: Files/Ballerina/bin/../distributions/ballerina-version: No such file or directory
/c/Program Files/Ballerina/bin/bal: line 123: /c/Program: No such file or directory
/c/Program Files/Ballerina/bin/bal: line 137: /c/Program: No such file or directory

f-schnabel avatar Oct 10 '24 12:10 f-schnabel

Locally I got it working by creating a bal file in the bin folder with the following content:

cmd "bal.bat"

This will proxy to the actual bat file. Any other solution I tried did not work:

  • Creating a shortcut for bal.bat called bal does not work. The shortcut always has the extension .lnk and therefore is not found by Git Bash
  • Copying the Linux bal script does not work since spaces are not correctly escaped
  • Copying the Windows bal.bat script and renaming it to bal does not work since GitBash does not recognize it as a bat file without the extension.

With the proposed solution, all cli arguments are forwarded to the bal.bat script and stdout/stderr/returncode are also forwarded as expected.

f-schnabel avatar Oct 10 '24 13:10 f-schnabel