User forums > General (but related to Code::Blocks)

The shebang command to run the bash script under Windows CMD

(1/1)

ollydbg:
Hi, I just noticed that there is a nice project named:   https://github.com/matveyt/shebang

With this project, we can run bash script from normal Windows CMD.

Here is my test which can correctly run "wx-config-3.1"(this is a bash script) from Windows CMD.

Step 1, get and build the shebang project

You just clone/download this project.

Under your local folder, inside the msys2's mingw64 compiler command line(started by double click the "mingw64.exe" under msys2 folder)


--- Code: ---gcc -s shebang.c -o shebang.exe -lshlwapi -DUNICODE -D_UNICODE -municode
--- End code ---

This will generate a "shebang.exe" in the same folder.


Step 2, rename this "shebang.exe" to the bash script executable name you want

I notice in my msys2's folder, there is a bash file named:  "F:\msys2\mingw64\bin\wx-config", this file is for wx 3.0, and since I have installed wx 3.1 from pacman, there is another file named "F:\msys2\mingw64\bin\wx-config-3.1".

Now, let me try with the later script file "wx-config-3.1".

I need to copy/rename the "shebang.exe" to "wx-config-3.1.exe"

Step 3, prepare the PATH

I just start the Windows CMD window, and type something like:


--- Code: ---set PATH=F:\msys2\usr\bin;F:\msys2\mingw64\bin;%PATH%
--- End code ---

This will put the necessary tools in the PATH

Step 4, run the "wx-config-3.1.exe" from the CMD

Now, you can type such command inside your CMD


--- Code: ---D:\code\shebang-master>wx-config-3.1.exe --cflags
-I/mingw64/lib/wx/include/msw-unicode-3.1 -I/mingw64/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__

D:\code\shebang-master>wx-config-3.1.exe --libs
-L/mingw64/lib   -pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high -Wl,--subsystem,windows -mwindows -lwx_mswu_xrc-3.1 -lwx_mswu_html-3.1 -lwx_mswu_qa-3.1 -lwx_mswu_core-3.1 -lwx_baseu_xml-3.1 -lwx_baseu_net-3.1 -lwx_baseu-3.1
--- End code ---

You can see, when you run the wx-config-3.1.exe, it will internally call the msys' bash script engine.

One remaining bug:
If I run the the same command inside the msys2' mingw64 shell, I got this:



--- Code: ---# wx-config-3.1 --cflags
-IF:/msys2/mingw64/lib/wx/include/msw-unicode-3.1 -IF:/msys2/mingw64/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__
--- End code ---

So, it looks like the returned path is not the same in the two cases.

Any one knows how to fix this issue? Maybe, I need to add some options?




stahta01:
Try running the below in both places.


--- Code: ---wx-config-3.1 --prefix

--- End code ---

I used to use something like

--- Code: ---wx-config-3.1 --prefix=<COMPILERPATH> --libs

--- End code ---

Where <COMPILERPATH> was an CB variable.

Tim S.

ollydbg:
Hi, tim, thanks for the reply.

In-fact, I found the shebang project project on github because I see you star this project.  :)

I just try adding the "--prefix" option in Windows CMD, it gives nice result:


--- Code: ---D:\code\shebang-master>wx-config-3.1.exe --prefix=F:/msys2/mingw64/bin --cflags
-IF:/msys2/mingw64/bin/lib/wx/include/msw-unicode-3.1 -IF:/msys2/mingw64/bin/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__

D:\code\shebang-master>wx-config-3.1.exe --prefix=F:/msys2/mingw64/bin --libs
-LF:/msys2/mingw64/bin/lib   -pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high -Wl,--subsystem,windows -mwindows -lwx_mswu_xrc-3.1 -lwx_mswu_html-3.1 -lwx_mswu_qa-3.1 -lwx_mswu_core-3.1 -lwx_baseu_xml-3.1 -lwx_baseu_net-3.1 -lwx_baseu-3.1

--- End code ---

ollydbg:
The best way to use those results in C::B's option dialog is use some backtick option, such as:


--- Code: ---
`wx-config-3.1 --cflags --prefix=$(TARGET_COMPILER_DIR)`


--- End code ---

There are some similar method I tried before:


--- Code: ---
`wx-config-msys2 --cflags --prefix=$(TARGET_COMPILER_DIR)`


--- End code ---

Where the wx-config-msys2 comes from this eranif's project:  https://github.com/eranif/wx-config-msys2

ollydbg:

--- Quote from: ollydbg on September 11, 2021, 10:35:09 am ---

One remaining bug:
If I run the the same command inside the msys2' mingw64 shell, I got this:


--- Code: ---# wx-config-3.1 --cflags
-IF:/msys2/mingw64/lib/wx/include/msw-unicode-3.1 -IF:/msys2/mingw64/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__
--- End code ---

So, it looks like the returned path is not the same in the two cases.

Any one knows how to fix this issue? Maybe, I need to add some options?


--- End quote ---

This issue is fixed, see this github ticket: How to control the returned file path from shebang tool matveyt/shebang

The author of the shebang give me the solution.


--- Code: ---set PATH=F:\msys2\mingw64\bin;F:\msys2\usr\bin;%PATH%
--- End code ---

Just put the mingw64/bin path before msys2/usr/bin path.  ;)

Navigation

[0] Message Index

Go to full version