ballerina-lang
ballerina-lang copied to clipboard
Ballerina CLI as .bat file only cause command not found using Git Bash
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
This is not a bug. We do not support this now.
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?
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)
Looking into my installation folder I noticed that there is no
balfile inside thebinfolder, only thebal.batfile. I think we would need to add abalfile also in the windows distribution so it can be found and used by git bash. This file should be the same asbal.bat. ~Otherwise it would also be feasable to directly rename thebal.batfile tobalfor windows. This would also fix this issue~batscripts have to have this extension on windows, so we can't just rename it. We could create an alias and name the aliasbal(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
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
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.batcalledbaldoes not work. The shortcut always has the extension.lnkand therefore is not found by Git Bash - Copying the Linux
balscript does not work since spaces are not correctly escaped - Copying the Windows
bal.batscript and renaming it tobaldoes not work since GitBash does not recognize it as abatfile 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.